3D Graphics

WebGL

JWt uses WebGL to render 3D graphics in the browser. The class WGLWidget provides an interface for a 3D widget. Most of the functions provided by this class are a simple one-to-one map of the WebGL functions available in the browser.

The rendering process consists of four major parts, which should be implemented by overriding four virtual functions:

  • initializeGL(): This function is executed only once, when the widget is created.
  • resizeGL(): This function is called whenever the widget is resized
  • updateGL(): This function allows you to make state changes (e.g. to VBO's, shaders ...).
  • paintGL(): This function contains all necessary calls to do the actual painting. The effect of paintGL() is recorded on the server, but the generated JavaScript is repeatedly executed on the client without requiring client/server requests. This is for example used to rerender a scene client-side after changing the camera position

Server-side Fallback

When a browser does not support WebGL (e.g. IE10 or less, mobile browsers ...), WGLWidget provides a server-side fall-back. The image will then be rendered in the server and sent to the browser as an PNG. Interaction is still possible, but the performance will be determined by the network latency. Also note that for practical scenarios this requires a server with hardware 3D acceleration.