1 ! Copyright (C) 2008 Doug Coleman, Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays byte-arrays kernel math namespaces
4 opengl.gl sequences math.vectors ui images images.normalization
5 images.viewer models ui.gadgets.worlds ui.gadgets fry alien.syntax ;
8 : screenshot-array ( world -- byte-array )
9 dim>> [ first 4 * ] [ second ] bi * <byte-array> ;
11 : gl-screenshot ( gadget -- byte-array )
15 GL_PACK_ALIGNMENT 4 glPixelStorei
18 dim>> first2 GL_RGBA GL_UNSIGNED_BYTE
20 [ screenshot-array ] bi
21 [ glReadPixels ] keep ;
23 : screenshot ( window -- bitmap )
25 [ gl-screenshot >>bitmap ] [ dim>> >>dim ] bi
26 RGBA >>component-order
30 : screenshot. ( window -- )
31 [ screenshot <image-gadget> ] [ title>> ] bi open-window ;