Skip to content

Instantly share code, notes, and snippets.

@rdm
Last active August 29, 2015 14:17
Show Gist options
  • Save rdm/ef3fe864d337324771de to your computer and use it in GitHub Desktop.
Save rdm/ef3fe864d337324771de to your computer and use it in GitHub Desktop.
gl3lab_run''
get_pixels 10 10
require 'graphics/gl2 api/gles'
coinsert 'jgl2 jgles'
GL3LAB=: 0 : 0
pc gl3lab closeok;
minwh 200 200;cc g opengl compatibility flush;
pas 0 0;
rem form end;
)
gl3lab_run=: 3 : 0
wd GL3LAB
wd'pshow;'
)
gl3lab_close=: 3 : 0
smoutput 'close'
wd'pclose'
)
gl3lab_g_paint=: 3 : 0
smoutput 'paint'
g_draw_init gl_qwh''
g_draw''
)
NB. y is wh - cmds required for new render context
g_draw_init=: 3 : 0
smoutput 'init'
glViewport 0 0,y
)
g_draw=: 3 : 0
glClearColor 0 0 1 0
glClear GL_COLOR_BUFFER_BIT
glOrtho _1 1 _1 1 _1 1
glColor3d ?0 0 0
glBegin GL_POLYGON
glVertex3d 1,0,0
glVertex3d 0,1,0
glVertex3d _1,0,0
glEnd ''
)
NB. press Ctrl+f to report frames/second
gl3lab_fctrl_fkey=: 3 : 0
start=. 6!:1''
for. i.100 do.
gl_paint''
end.
time=. (6!:1'')-start
smoutput 'w h: ',(":gl_qwh''),' frames/sec: ',":100%time
)
NB. y is wh
NB. get pixels from pixel buffer render context
NB. see https://www.opengl.org/sdk/docs/man2/xhtml/glReadPixels.xml
NB. for a current spec of the underlying api
get_pixels=: 3 : 0
len=. */y,4
data=. mema len
glReadPixels 0,0,y,GL_RGB,GL_UNSIGNED_INT_8_8_8_8,data
r=. 256#.a.i.(y,4)$memr data,0,len
memf data
r
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment