1 ! Copyright (C) 2008 Doug Coleman, Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors byte-arrays images images.normalization
4 images.viewer kernel math namespaces opengl opengl.gl
5 sequences ui ui.gadgets.worlds ;
10 : screenshot-array ( world -- byte-array )
11 dim>> [ first 4 * ] [ second ] bi
12 [ gl-scale ] bi@ * >fixnum <byte-array> ;
14 : gl-screenshot ( gadget -- byte-array )
19 GL_PACK_ALIGNMENT 4 glPixelStorei
22 dim>> first2 [ gl-scale >fixnum ] bi@
23 GL_RGBA GL_UNSIGNED_BYTE
25 [ screenshot-array ] tri
26 [ glReadPixels ] keep ;
30 :: screenshot ( window -- bitmap )
32 gl-scale-factor get-global [ 2.0 = >>2x? ] when*
33 window gl-screenshot >>bitmap
34 window dim>> [ gl-scale >fixnum ] map >>dim
35 ubyte-components >>component-type
36 RGBA >>component-order
40 : screenshot. ( window -- )
41 [ screenshot <image-gadget> ] [ title>> ] bi open-window ;