OpenGL is a 3D graphics API. It is standard on Windows,Linux, and Mac OS X.
J uses the API with cd DLL call and the J programmer has the same access as a C programmer. OpenGL drawing is done on an opengl control. All API must be called with the presence of a valid OpenGL context.
Quick Start - Information for users
- For demos, run demo
NB. OpenGL 1.4 load '~addons/demos/glsimple/gldemos.ijs' NB. this require addon graphics/gl1ut load '~addons/demos/gldemo/gldemo.ijs'
NB. OpenGL 2.0 or higher load '~addons/ide/qt/demo/shader.ijs'
- OpenGL 2.0 or OpenGL ES 2.0
- OpenGL Shading Language (GLSL) for using programmable function pipeline in GPU
- most glu_... helper APIs removed in OpenGL 3.1 and OpenGL ES 2.0
- use vertex buffer object instead of immediate mode (glBegin/glVertex../glEnd)
- not available in virtual machines such as virtualbox.
OpenGL ES 2.0
- used in embedded devices such as Android 2.1 and iPhone 3GS or higher
- a subset of desktop version OpenGL
- can only draw triangles, thus polygon or sphere has to be drawn by using strips of triangles.
- OpenGL 1.4
NB. legacy OpenGL API require 'gl3' coinsert 'jgl3'
or if it uses gl1ut
NB. legacy OpenGL API require 'graphics/gl1ut' coinsert 'jgl1ut'
- OpenGL 2.0/OpenGL ES 2.0
NB. modern OpenGL API require 'gles' coinsert 'jgles'
child class opengl which is derived from Qt QGLWidget
wd 'pc form closeok' wd 'minwh 300 300' NB. minimum size in pixels wd 'cc g opengl flush'
- newer video cards can provide a compatibility profile to reinstate some removed legacy OpenGL APIs.
wd 'cc g opengl compatibility flush'
- provide 4 OpenGL related events - initialize, size, paint, paintz
form_g_initialize=: 3 : 0 NB. load extensions, query glGetString, compile shader, setting up buffers, etc... ) form_g_size=: 3 : 0 NB. size of widget changed ) form_g_paint=: 3 : 0 NB. draw on OpenGL context ) form_g_paintz=: 3 : 0 NB. called after paint finished NB. GL_DEPTH_TEST must be disabled otherwise invisible NB. use gl2 commands to draw on overlay such as text NB. these gl2 commands for opengl are the same as the regular gl2 commands NB. but with prefix gl_ instead of gl, eg NB. gl_clear, gl_text )
- used in OpenGL(ES) 2, provide verbs for manipulating 4x4 matrix
- matrix is row-major and pre-multiplication with vector
- no need to transpose when passing to OpenGL
layout of 16 element vector (0-base): m0 m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14 m15
gl_I - load identity matrix, argument ignored.
the following are dyad, left argument is gl_I'' if elided
gl_Rotate angle,x,y,z - angle in degree
- used in OpenGL(ES) 2, similar APIs have been removed since OpenGL ES 2.0 or OpenGL 3.1
dyad, left argument is gl_I'' if elided
- used in OpenGL(ES) 2
wglPROC - load extension APIs dynamically for windows, should be called inside the initialize event.
glu_LookAt eye, center, up
Comparison with J6
- class jzopengl and jzopenutil have been decommitted. Functions of jzopenutil are provided in a new addon graphics/gl1ut which is only intended for legacy OpenGL API.
OpenGL context is managed by Qt, no need to call ''conew'jzopengl'
- Modern API - supports shader but steeper learning curve
Contributed by BillLam.