Update Unicode docs
[factor/jcg.git] / extra / bunny / bunny.factor
blobd0625e464f7e14febdba943c8871ef6da6201b2d
1 USING: accessors arrays bunny.cel-shaded bunny.fixed-pipeline
2 bunny.model bunny.outlined destructors kernel math opengl.demo-support
3 opengl.gl sequences ui ui.gadgets ui.gadgets.worlds ui.gestures
4 ui.render words ;
5 IN: bunny
7 TUPLE: bunny-gadget < demo-gadget model-triangles geom draw-seq draw-n ;
9 : <bunny-gadget> ( -- bunny-gadget )
10     0.0 0.0 0.375 bunny-gadget new-demo-gadget
11     maybe-download read-model >>model-triangles ;
13 : bunny-gadget-draw ( gadget -- draw )
14     [ draw-n>> ] [ draw-seq>> ] bi nth ;
16 : bunny-gadget-next-draw ( gadget -- )
17     dup [ draw-seq>> ] [ draw-n>> ] bi
18     1+ swap length mod
19     >>draw-n relayout-1 ;
21 M: bunny-gadget graft* ( gadget -- )
22     dup find-gl-context
23     GL_DEPTH_TEST glEnable
24     dup model-triangles>> <bunny-geom> >>geom
25     dup
26     [ <bunny-fixed-pipeline> ]
27     [ <bunny-cel-shaded> ]
28     [ <bunny-outlined> ] tri 3array
29     sift >>draw-seq
30     0 >>draw-n
31     drop ;
33 M: bunny-gadget ungraft* ( gadget -- )
34     dup find-gl-context
35     [ geom>> [ dispose ] when* ]
36     [ draw-seq>> [ [ dispose ] when* ] each ] bi ;
38 M: bunny-gadget draw-gadget* ( gadget -- )
39     dup draw-seq>> empty? [ drop ] [
40         0.15 0.15 0.15 1.0 glClearColor
41         GL_DEPTH_BUFFER_BIT GL_COLOR_BUFFER_BIT bitor glClear
42         dup demo-gadget-set-matrices
43         GL_MODELVIEW glMatrixMode
44         0.02 -0.105 0.0 glTranslatef
45         [ geom>> ] [ bunny-gadget-draw ] bi draw-bunny
46     ] if ;
48 M: bunny-gadget pref-dim* ( gadget -- dim )
49     drop { 640 480 } ;
50     
51 bunny-gadget H{
52     { T{ key-down f f "TAB" } [ bunny-gadget-next-draw ] }
53 } set-gestures
55 : bunny-window ( -- )
56     [ <bunny-gadget> "Bunny" open-window ] with-ui ;
58 MAIN: bunny-window