]> gitweb.factorcode.org Git - factor.git/blob - extra/nehe/2/2.factor
8be2970b92b3690dc5e9731b6140452bb9123c89
[factor.git] / extra / nehe / 2 / 2.factor
1 USING: arrays kernel math opengl opengl.gl opengl.glu
2 opengl.demo-support ui ui.gadgets ui.render ui.pixel-formats
3 literals accessors ;
4 IN: nehe.2
5
6 TUPLE: nehe2-gadget < gadget ;
7
8 CONSTANT: width 256
9 CONSTANT: height 256
10
11 : <nehe2-gadget> (  -- gadget )
12     nehe2-gadget new ;
13
14 M: nehe2-gadget draw-gadget* ( gadget -- )
15     drop
16     GL_PROJECTION glMatrixMode
17     glLoadIdentity
18     45.0 width height / >float 0.1 100.0 gluPerspective
19     GL_MODELVIEW glMatrixMode
20     glLoadIdentity
21     GL_SMOOTH glShadeModel
22     0.0 0.0 0.0 0.0 glClearColor
23     1.0 glClearDepth
24     GL_DEPTH_TEST glEnable
25     GL_LEQUAL glDepthFunc
26     GL_PERSPECTIVE_CORRECTION_HINT GL_NICEST glHint
27     GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT bitor glClear
28     glLoadIdentity
29     -1.5 0.0 -6.0 glTranslatef
30     GL_TRIANGLES [
31         0.0 1.0 0.0 glVertex3f
32         -1.0 -1.0 0.0 glVertex3f
33         1.0 -1.0 0.0 glVertex3f
34     ] do-state
35     3.0 0.0 0.0 glTranslatef
36     GL_QUADS [
37         -1.0 1.0 0.0 glVertex3f
38         1.0 1.0 0.0 glVertex3f
39         1.0 -1.0 0.0 glVertex3f
40         -1.0 -1.0 0.0 glVertex3f
41     ] do-state ;
42
43 MAIN-WINDOW: run2
44     {
45         { title "NeHe Tutorial 2" }
46         { pref-dim { $ width $ height } }
47         { pixel-format-attributes {
48             windowed
49             double-buffered
50             T{ depth-bits { value 16 } }
51         } }
52     }
53     <nehe2-gadget> >>gadgets ;