It woudl be useful to do some OpenGL work outside of the four methods defined by GLEventListener. Is there a way to define textures, vbos, shaders, etc using just by calling methods on the GLCanvas or Pbuffer? At the moment, I’ve created a message queue that I’m using to buffer things I want to do wwhen I’m outside of display(), and then executing all of them the next time the display() method runs.
You can call getContext() to get the GLContext and makeCurrent() / release() on it manually. Note that you must check the return code from makeCurrent(), and that doing this can interfere with the GLEventListener mechanism (in particular, processing of GLEventListener.init() calls). It’s also better if you use the Threading class to run your Runnables which do the context-related work for best robustness across platforms.
Do you mean something like:
if (glContext.makeCurrent() != GLContext.CONTEXT_NOT_CURRENT)
{
Threading.invokeOnOpenGLThread(
new Runnable()
{
public void run()
{
GL gl = glContext.getGL();
//do stuff with gl
}
}
);
glContext.release();
}
Will this work? Or did you mean something else? I can’t find much information on either GLConext or Threading.
No, move the use of the GLContext and the makeCurrent() call into the Runnable callback and reference the surrounding state you need via final variables in the method you’re currently in. Take a look at the GLCanvas source code for an example of how to use the Threading class.