J6/OpenGL/Class

From J Wiki
Jump to: navigation, search
J6/OpenGL  | Class  | API  | Utils   Movement   Viewing


Load

The jzopengl class manages an OpenGL render context (drawing context) and provides various utilities. Load with:

load 'jzopengl'

Make "gl*" names available:

coinsert 'jgl3'

Method

OpenGL drawing is done on an isigraph control with the opengl style. For example:

WGL=: 0 : 0
pc wgl;
xywh 0 0 100 100;cc g isigraph opengl rightmove bottommove;
)

An instance of the jzopen class is needed. Typically, this is created in the form run verb, and assigned to global ogl:

wgl_run=: 3 : 0
wd WGL
ogl=: ''conew'jzopengl'
wd'pshow;'
)

The isigraph paint method is used to draw the control, and calls the required opengl commands:

wgl_g_paint=: 3 : 0
if. rc__ogl'' do.
  g_draw_init wh__ogl
end.
g_draw''
show__ogl''
)

g_draw_init=: 3 : 0
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
glVertex 1 0 0, 0 1 0 ,:_1 0 0
glEnd ''
)

Close should destroy the opengl instance:

wgl_close=: 3 : 0
destroy__ogl''
wd'pclose'
)

Verbs

Main verbs are:

create, destroy  - create and destroy a jzopengl instance.

rc  - set render context. Result is 1 if a new render context (a new drawing, or form resize), else 0.

show  - show drawing on screen.

Other verbs:

pixels  - return current drawing as pixels.

Nouns

Main nouns are:

wh  - isigraph control width, height