]> gitweb.factorcode.org Git - factor.git/blob - extra/cap/cap.factor
f558342bb19b6c958b6b1cd99475793c3c8c3d39
[factor.git] / extra / cap / cap.factor
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
6 ui.gadgets.worlds ;
7 IN: cap
8
9 : screenshot-array ( world -- byte-array )
10     dim>> [ first 4 * ] [ second ] bi
11     [ gl-scale ] bi@ * >fixnum <byte-array> ;
12
13 : gl-screenshot ( gadget -- byte-array )
14     [
15         [
16             GL_BACK glReadBuffer
17             GL_PACK_ALIGNMENT 4 glPixelStorei
18             0 0
19         ] dip
20         dim>> first2 [ gl-scale >fixnum ] bi@
21         GL_RGBA GL_UNSIGNED_BYTE
22     ]
23     [ screenshot-array ] bi
24     [ glReadPixels ] keep ;
25
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
32     t >>upside-down?
33     normalize-image ;
34
35 : screenshot. ( window -- )
36     [ screenshot <image-gadget> ] [ title>> ] bi open-window ;