PageRenderTime 30ms CodeModel.GetById 16ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/extra/bunny/bunny.factor

http://github.com/abeaumont/factor
Unknown | 60 lines | 51 code | 9 blank | 0 comment | 0 complexity | 76b5f39d17a5262e84f07755b3155a04 MD5 | raw file
 1USING: accessors arrays bunny.cel-shaded bunny.fixed-pipeline
 2bunny.model bunny.outlined destructors kernel math opengl.demo-support
 3opengl.gl sequences ui ui.gadgets ui.gadgets.worlds ui.gestures
 4ui.render words ui.pixel-formats ;
 5IN: bunny
 6
 7TUPLE: 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
23M: bunny-world begin-world
24    GL_DEPTH_TEST glEnable
25    0.0 0.0 0.375 set-demo-orientation
26    maybe-download read-model
27    [ >>model-triangles ] [ <bunny-geom> >>geom ] bi
28    dup make-draws >>draw-seq
29    0 >>draw-n
30    drop ;
31
32M: bunny-world end-world
33    dup find-gl-context
34    [ geom>> [ dispose ] when* ]
35    [ draw-seq>> [ [ dispose ] when* ] each ] bi ;
36
37M: bunny-world draw-world*
38    dup draw-seq>> empty? [ drop ] [
39        0.15 0.15 0.15 1.0 glClearColor
40        GL_DEPTH_BUFFER_BIT GL_COLOR_BUFFER_BIT bitor 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
47bunny-world H{
48    { T{ key-down f f "TAB" } [ next-draw ] }
49} set-gestures
50
51MAIN-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    } ;