1 ! Copyright (C) 2008 Doug Coleman, Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.syntax arrays byte-arrays fry images
4 images.normalization images.viewer kernel math math.vectors
5 models namespaces opengl opengl.gl sequences ui ui.gadgets
9 : screenshot-array ( world -- byte-array )
10 dim>> [ first 4 * ] [ second ] bi
11 [ gl-scale ] bi@ * >fixnum <byte-array> ;
13 : gl-screenshot ( gadget -- byte-array )
17 GL_PACK_ALIGNMENT 4 glPixelStorei
20 dim>> first2 [ gl-scale >fixnum ] bi@
21 GL_RGBA GL_UNSIGNED_BYTE
23 [ screenshot-array ] bi
24 [ glReadPixels ] keep ;
26 : screenshot ( window -- bitmap )
27 [ <image> t >>2x? ] dip
28 [ gl-screenshot >>bitmap ]
29 [ dim>> [ gl-scale >fixnum ] map >>dim ] bi
30 ubyte-components >>component-type
31 RGBA >>component-order
35 : screenshot. ( window -- )
36 [ screenshot <image-gadget> ] [ title>> ] bi open-window ;