require 'gl3'

A=: noun define
pc a closeok;
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
glViewport 0 0,glqwh''
glMatrixMode GL_PROJECTION
glLoadIdentity''
gluPerspective 60 1 1 30
glMatrixMode GL_MODELVIEW
glLoadIdentity''
glTranslate 0 0 _3.6
)

a_g_paint=:verb define
texture ''
glaSwapBuffers''
)

w=.8 8$_1
b=.8 8$0
pattern=: ,64 64$,   (8 64$,w,.b),8 64$,b,.w

NB. note GL_RGBA so that pattern is 1 integer per texel
texture=:verb define
glClearColor 0 0 0 0
glEnable GL_DEPTH_TEST
glDepthFunc GL_LEQUAL
glPixelStore GL_UNPACK_ALIGNMENT, 1

glTexImage2D (GL_TEXTURE_2D, 0 3 64 64 0, GL_RGBA, GL_UNSIGNED_BYTE) ; pattern

glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP
glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP
glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST
glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST

glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL
glEnable GL_TEXTURE_2D
glShadeModel GL_FLAT

glClear GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT
glBegin GL_QUADS

glTexCoord 0 0 0 1
glVertex _2 _1  0

glTexCoord 0 1 0 1
glVertex _2  1  0

glTexCoord 1 1 0 1
glVertex  0  1  0

glTexCoord 1 0 0 1
glVertex  0 _1 0


glTexCoord 0 0 0 1
glVertex  1 _1  0

glTexCoord 0 1 0 1
glVertex  1  1  0

glTexCoord 1 1 0 1
glVertex  2.41421  1 _1.41421

glTexCoord 1 0 0 1
glVertex  2.41421 _1 _1.41421

glEnd''
)

a_run''
