require 'gl3'

A=: noun define
pc a closeok;
menupop "&Help";
menu help "&Help" "" "" "";
menupopz;
xywh 0 0 100 100;cc g isigraph ws_clipchildren ws_clipsiblings rightmove bottommove;
pas 0 0;
rem form end;
)

a_run=: verb define
wd A
glaRC''
R =: 20 30 0
wd 'pshow;ptop'
)

a_g_char =: verb define
R =: 360 | R + 2 * 'xyz' = 0 { sysdata
glpaintx''
)

a_g_size=:verb define
wh=.glqwh''
glViewport 0 0,wh
glMatrixMode GL_PROJECTION
glLoadIdentity''
gluPerspective 30, (%/wh),1 10
)

a_g_paint =: verb define
glClearColor 1 1 1 0
glClear GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT
glEnable GL_DEPTH_TEST
glMatrixMode GL_MODELVIEW
glLoadIdentity''
glTranslate 0 0 _8
glRotate R ,. 3 3 $ 1 0 0 0
light''
drawbox ''
glaSwapBuffers ''
)

light=: verb define
glLight GL_LIGHT0, GL_AMBIENT, 0.1 0.1 0.1 1
glLight GL_LIGHT0, GL_DIFFUSE, 0.7 0.7 0.7 1
glLight GL_LIGHT0,GL_SPECULAR, 0.0 0.0 0.0 1
glEnable GL_LIGHTING
glEnable GL_LIGHT0
glMaterial GL_FRONT,GL_AMBIENT_AND_DIFFUSE, 1 0 0 1
)

BLUE=:  0 0 1
GREEN=: 0 1 0
RED=:   1 0 0

drawbox=:verb define
p=. _1 ^ #: i.8

n0=.  1  0  0
n1=.  0  1  0
n2=.  0  0  1
n3=.  _1 0  0
n4=.  0  0 _1
n5=.  0 _1  0

glMaterial GL_FRONT,GL_AMBIENT_AND_DIFFUSE, 1 0 0 1
glColor 1 0 0 1
n0 polygonnormal 0 1 3 2{p
n1 polygonnormal 0 1 5 4{p
n2 polygonnormal 0 2 6 4{p
n3 polygonnormal 4 5 7 6{p
n4 polygonnormal 1 3 7 5{p
n5 polygonnormal 2 3 7 6{p
)

polygonnormal=: 4 : 0
glBegin GL_POLYGON
glNormal x.
y=. y.
while. #y do.
 glVertex 3{.y
 y=. 3}.y
end.
glEnd''
)

a_help_button=: verb define
wd'mb OpenGL *Press the x y and z keys to rotate the cube.'
wd 'setfocus g'
)

a_run''
