help.html: only input.focus().
[factor.git] / extra / bunny / bunny.factor
1 USING: accessors arrays bunny.cel-shaded bunny.fixed-pipeline
2 bunny.model bunny.outlined destructors kernel literals math
3 opengl.demo-support opengl.gl sequences ui ui.gadgets
4 ui.gadgets.worlds ui.gestures ui.pixel-formats ;
5 IN: bunny
6
7 TUPLE: bunny-world < demo-world model-triangles geom draw-seq draw-n ;
8
9 : get-draw ( gadget -- draw )
10     [ draw-n>> ] [ draw-seq>> ] bi nth ;
11
12 : next-draw ( gadget -- )
13     dup [ draw-seq>> ] [ draw-n>> ] bi
14     1 + swap length mod
15     >>draw-n relayout-1 ;
16
17 : make-draws ( gadget -- draw-seq )
18     [ <bunny-fixed-pipeline> ]
19     [ <bunny-cel-shaded> ]
20     [ <bunny-outlined> ] tri 3array
21     sift ;
22
23 M: bunny-world begin-world
24     GL_DEPTH_TEST glEnable
25     0.0 0.0 0.375 set-demo-orientation
26     download-bunny read-model
27     [ >>model-triangles ] [ <bunny-geom> >>geom ] bi
28     dup make-draws >>draw-seq
29     0 >>draw-n
30     drop ;
31
32 M: bunny-world end-world
33     dup find-gl-context
34     [ geom>> [ dispose ] when* ]
35     [ draw-seq>> [ [ dispose ] when* ] each ] bi ;
36
37 M: bunny-world draw-world*
38     dup draw-seq>> empty? [ drop ] [
39         0.15 0.15 0.15 1.0 glClearColor
40         flags{ GL_DEPTH_BUFFER_BIT GL_COLOR_BUFFER_BIT } glClear
41         dup demo-world-set-matrix
42         GL_MODELVIEW glMatrixMode
43         0.02 -0.105 0.0 glTranslatef
44         [ geom>> ] [ get-draw ] bi draw-bunny
45     ] if ;
46
47 bunny-world H{
48     { T{ key-down f f "TAB" } [ next-draw ] }
49 } set-gestures
50
51 MAIN-WINDOW: bunny-window {
52     { world-class bunny-world }
53     { title "Bunny" }
54     { pixel-format-attributes {
55         windowed
56         double-buffered
57         T{ depth-bits { value 16 } }
58     } }
59     { pref-dim { 640 480 } }
60 } ;