factor/extra/cap/cap.factor

31 lines
911 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
opengl.gl sequences math.vectors ui graphics.bitmap graphics.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 -- )
2008-11-01 16:48:35 -04:00
[ screenshot <graphics-gadget> ] [ title>> ] bi open-window ;