OpenGL is a 3D graphics API. It is standard on Linux, Mac OSX and Android. Windows require vendor graphics drivers support. See below.
The full version of Jqt should be installed, see Slim_vs_Full_Builds.
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.
OpenGL 1.x and glu... APIs used in J602 had been desupported since J803. If your OpenGL programs do not contain any shader, they probably will not work.
Quick Start - Information for users
- For demos, run
Menu > Help > Studio > Qt Demos... > shader
- OpenGL 2.0 or newer, the current version is 4.5 (released on August 2014)
- OpenGL Shading Language (GLSL) for using programmable function pipeline in GPU
- current version supports vertex, fragment, geometry, tessellation control, tessellation evaluation and compute shaders
- OpenGL ES 2.0 or newer, the current version is 3.1 (released on March 2014)
- used in embedded devices such as Android and iPhone
- a subset of desktop version OpenGL
- geometry and tessellation shaders are not currently supported in 3.1
- WebGL runs inside browsers exposed through the HTML5 Canvas element
- does NOT use or require api/gles addon or opengl widget for working
- simple demos available in ide/jhs and ide/qt addons
Dynamically Loading Graphics Drivers (Windows platform)
By default, Qt will determine whether the system's opengl32.dll provides OpenGL 2 functions. If these are present, opengl32.dll is used, otherwise the ANGLE libraries will be used. In case the ANGLE libraries are missing or initialization fails for some reason, an additional fallback is attempted by trying to load opengl32sw.dll.
The loading mechanism can be configured through the QT_OPENGL environment variable:
When a certain configuration is requested explicitly, no checks are done at application startup, that is, the system-provided opengl32.dll will not be examined.
- addon api/gles provides OpenGL/OpenGL ES function prototypes and constants
- utilities for matrix transfomation and projection are also provided
require 'gles' coinsert 'jgles'
Window Driver Widget
- child class opengl which provides the OpenGL context and event callback
wd 'pc form' wd 'minwh 300 300' NB. minimum size in pixels wd 'cc g opengl flush'
- optional parameter for setting OpenGL version. Note that OpenGL driver may fall back to another version.
wd 'cc g opengl version 3.3 flush'
- provide 3 OpenGL related events - initialize, resize, paint
- Keyboard and mouse events similar to that in isigraph/isidraw are also provided
form_g_initialize=: 3 : 0 NB. load extensions, query glGetString, compile shader, setting up buffers, etc... NB. since different versions of GLSL are incompatible with each other, NB. it needs to query the version of GLSL here and execute different codes. ) form_g_resize=: 3 : 0 NB. size of widget changed ) form_g_paint=: 3 : 0 NB. OpenGL stuff here NB. draw on OpenGL context NB. NB. additional overlay: NB. use gl2 commands to draw on top of OpenGL surface such as text NB. these gl2 commands for OpenGL overlay are similar to regular gl2 commands NB. but with prefix gl_ instead of gl, eg NB. gl_clear, gl_text NB. GL_DEPTH_TEST must be disabled for overlay otherwise invisible )
- APIs for handling matrix had been removed from OpenGL
- api/gles addon provides verbs for manipulating 4x4 matrix
- matrix is row-major and pre-multiplication with vector (see also: opengl transformations faq)
- 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_Translate x,y,z
- gl_Rotate angle,x,y,z - angle in degree
- gl_Scale f
- similar APIs have been removed since OpenGL ES 2.0 or OpenGL 3.1
- dyad, left argument is gl_I'' if elided
- gl_Perspective fovy,aspect,znear,zfar
- gl_Frustum left,right,bottom,top,near,far
- gl_Ortho left,right,bottom,top,near,far
- wglPROC - load extension APIs dynamically for windows, should be called inside the initialize event.
- glu_LookAt eye, center, up
Contributed by Bill Lam.