Contents / Previous / Next


Interaction

When only direct interaction moves the scene the repaint-on-demand model should be used to save CPU time. The application calls GLAutoDrawable.display() manually at the end of the mouse or keyboard listener to cause repainting to be done.

In any case (any repaint strategy) OpenGL rendering is done on the main "this" thread rather than on the internal AWT event queue thread which dispatches mouse and keyboard events
=> OpenGL rendering may not occur directly inside the mouse or keyboard handlers!

Applications should perform as little work as possible inside their mouse and keyboard handlers to keep the GUI responsive.
The best practice is to store off state when the listener is entered and retrieve this state during the next call to GLEventListener.display().

If there are long computational sequences in the GLEventListener's display method which reference variables which may be being simultaneously modified by the AWT thread (mouse and keyboard listeners), copies of these variables be made upon entry to display and these copies be referenced throughout display() and the methods it calls.
This will prevent the values from changing (by user interaction) while the OpenGL rendering is being performed. Errors of this kind show up in many ways, including certain kinds of flickering of the rendered image as certain pieces of objects are rendered in one place and other pieces are rendered elsewhere in the scene.

    ...

    if (e.getKeyChar() == 'r') {
	commandMediator.lookRight();
	 redisplay();
    }    
    ....

    private void redisplay()
    {
        canvas.display();
    }