factor/extra/cap/cap.factor

32 lines
924 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 images 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 )
dim>> [ first 4 * ] [ second ] bi * <byte-array> ;
2008-10-30 19:16:03 -04:00
: gl-screenshot ( gadget -- byte-array )
[
[
GL_BACK glReadBuffer
GL_PACK_ALIGNMENT 4 glPixelStorei
0 0
] dip
dim>> first2 GL_RGBA GL_UNSIGNED_BYTE
]
2008-10-30 19:16:03 -04:00
[ screenshot-array ] bi
[ glReadPixels ] keep ;
: screenshot ( window -- bitmap )
[ <image> ] dip
[ gl-screenshot >>bitmap ] [ dim>> >>dim ] bi
RGBA >>component-order
t >>upside-down?
normalize-image ;
2008-10-30 19:16:03 -04:00
: screenshot. ( window -- )
2009-02-09 22:26:52 -05:00
[ screenshot <image-gadget> ] [ title>> ] bi open-window ;