factor/extra/cap/cap.factor

31 lines
904 B
Factor
Raw Normal View History

2008-11-01 16:48:35 -04:00
! Copyright (C) 2008 Doug Coleman, Joe Groff.
! See http://factorcode.org/license.txt for BSD license.
2008-10-30 19:16:03 -04:00
USING: accessors arrays byte-arrays kernel math namespaces
2009-02-09 22:26:52 -05:00
opengl.gl sequences math.vectors ui images.bitmap images.viewer
2008-12-03 01:06:08 -05:00
models ui.gadgets.worlds ui.gadgets fry alien.syntax ;
2008-10-30 19:16:03 -04:00
IN: cap
: screenshot-array ( world -- byte-array )
2008-11-18 21:35:41 -05:00
dim>> [ first 3 * 4 align ] [ second ] bi * <byte-array> ;
2008-10-30 19:16:03 -04:00
: gl-screenshot ( gadget -- byte-array )
[
GL_BACK glReadBuffer
2008-11-01 16:48:35 -04:00
GL_PACK_ALIGNMENT 4 glPixelStorei
2008-10-30 19:16:03 -04:00
0 0
] dip
[ dim>> first2 GL_BGR GL_UNSIGNED_BYTE ]
[ screenshot-array ] bi
[ glReadPixels ] keep ;
: screenshot ( window -- bitmap )
[ gl-screenshot ]
[ dim>> first2 ] bi
bgr>bitmap ;
: save-screenshot ( window path -- )
[ screenshot ] dip save-bitmap ;
: screenshot. ( window -- )
2009-02-09 22:26:52 -05:00
[ screenshot <image-gadget> ] [ title>> ] bi open-window ;