factor/extra/nehe/5/5.factor

125 lines
3.0 KiB
Factor
Raw Normal View History

USING: arrays kernel math opengl opengl.gl opengl.glu
opengl.demo-support ui ui.gadgets ui.render threads accessors
calendar literals ;
2007-09-20 18:09:08 -04:00
IN: nehe.5
2008-07-12 02:29:25 -04:00
TUPLE: nehe5-gadget < gadget rtri rquad thread quit? ;
CONSTANT: width 256
CONSTANT: height 256
2008-11-24 03:03:08 -05:00
: redraw-interval ( -- dt ) 10 milliseconds ;
2007-09-20 18:09:08 -04:00
: <nehe5-gadget> ( -- gadget )
nehe5-gadget new
2008-08-30 22:59:00 -04:00
0.0 >>rtri
0.0 >>rquad ;
2007-09-20 18:09:08 -04:00
M: nehe5-gadget draw-gadget* ( gadget -- )
GL_PROJECTION glMatrixMode
glLoadIdentity
45.0 width height / >float 0.1 100.0 gluPerspective
GL_MODELVIEW glMatrixMode
glLoadIdentity
GL_SMOOTH glShadeModel
0.0 0.0 0.0 0.0 glClearColor
1.0 glClearDepth
GL_DEPTH_TEST glEnable
GL_LEQUAL glDepthFunc
GL_PERSPECTIVE_CORRECTION_HINT GL_NICEST glHint
GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT bitor glClear
glLoadIdentity
-1.5 0.0 -6.0 glTranslatef
2008-09-02 13:14:54 -04:00
dup rtri>> 0.0 1.0 0.0 glRotatef
2007-09-20 18:09:08 -04:00
GL_TRIANGLES [
1.0 0.0 0.0 glColor3f
0.0 1.0 0.0 glVertex3f
0.0 1.0 0.0 glColor3f
-1.0 -1.0 1.0 glVertex3f
0.0 0.0 1.0 glColor3f
1.0 -1.0 1.0 glVertex3f
1.0 0.0 0.0 glColor3f
0.0 1.0 0.0 glVertex3f
0.0 0.0 1.0 glColor3f
1.0 -1.0 1.0 glVertex3f
0.0 1.0 0.0 glColor3f
1.0 -1.0 -1.0 glVertex3f
1.0 0.0 0.0 glColor3f
0.0 1.0 0.0 glVertex3f
0.0 1.0 0.0 glColor3f
1.0 -1.0 -1.0 glVertex3f
0.0 0.0 1.0 glColor3f
-1.0 -1.0 -1.0 glVertex3f
1.0 0.0 0.0 glColor3f
0.0 1.0 0.0 glVertex3f
0.0 0.0 1.0 glColor3f
-1.0 -1.0 -1.0 glVertex3f
0.0 1.0 0.0 glColor3f
-1.0 -1.0 1.0 glVertex3f
] do-state
glLoadIdentity
1.5 0.0 -7.0 glTranslatef
2008-09-02 13:35:14 -04:00
dup rquad>> 1.0 0.0 0.0 glRotatef
2007-09-20 18:09:08 -04:00
GL_QUADS [
0.0 1.0 0.0 glColor3f
1.0 1.0 -1.0 glVertex3f
-1.0 1.0 -1.0 glVertex3f
-1.0 1.0 1.0 glVertex3f
1.0 1.0 1.0 glVertex3f
1.0 0.5 0.0 glColor3f
1.0 -1.0 1.0 glVertex3f
-1.0 -1.0 1.0 glVertex3f
-1.0 -1.0 -1.0 glVertex3f
1.0 -1.0 -1.0 glVertex3f
1.0 0.0 0.0 glColor3f
1.0 1.0 1.0 glVertex3f
-1.0 1.0 1.0 glVertex3f
-1.0 -1.0 1.0 glVertex3f
1.0 -1.0 1.0 glVertex3f
1.0 1.0 0.0 glColor3f
1.0 -1.0 -1.0 glVertex3f
-1.0 -1.0 -1.0 glVertex3f
-1.0 1.0 -1.0 glVertex3f
1.0 1.0 -1.0 glVertex3f
0.0 0.0 1.0 glColor3f
-1.0 1.0 1.0 glVertex3f
-1.0 1.0 -1.0 glVertex3f
-1.0 -1.0 -1.0 glVertex3f
-1.0 -1.0 1.0 glVertex3f
1.0 0.0 1.0 glColor3f
1.0 1.0 -1.0 glVertex3f
1.0 1.0 1.0 glVertex3f
1.0 -1.0 1.0 glVertex3f
1.0 -1.0 -1.0 glVertex3f
] do-state
2008-08-30 22:59:00 -04:00
[ 0.2 + ] change-rtri
[ 0.15 - ] change-rquad drop ;
2007-09-20 18:09:08 -04:00
: nehe5-update-thread ( gadget -- )
2008-08-30 22:59:00 -04:00
dup quit?>> [
2008-02-06 20:23:39 -05:00
drop
] [
2007-09-20 18:09:08 -04:00
redraw-interval sleep
dup relayout-1
nehe5-update-thread
2008-02-06 20:23:39 -05:00
] if ;
2007-09-20 18:09:08 -04:00
M: nehe5-gadget graft* ( gadget -- )
2008-08-30 22:59:00 -04:00
f >>quit?
2008-09-11 16:36:42 -04:00
[ nehe5-update-thread ] curry in-thread ;
2007-09-20 18:09:08 -04:00
M: nehe5-gadget ungraft* ( gadget -- )
2008-08-30 22:59:00 -04:00
t >>quit? drop ;
2007-09-20 18:09:08 -04:00
MAIN-WINDOW: run5 { { title "NeHe Tutorial 5" } { pref-dim { $ width $ height } } }
<nehe5-gadget> >>gadgets ;