Is it possible to create a thread that does continuous rendering with a cached GL context? I'm trying to add PC support to my game that is using OpenGL ES for BlackBerry and Android. It's a pretty large change for me to try and support paint methods.
- Make sure your window is set not to erase its background (so the windowing system won't overwrite your GL graphics unpredictably)
- Create a rendering thread (separate from the windowing system's main thread)
- Create a GL context and make it current on your rendering thread
- Render continuously in a loop
However, depending on your app, you might still need callbacks. If your app is windowed instead of full-screen, you'd need a resize callback to adjust the OpenGL viewport, and a paint callback to re-render when the user drags another window across yours.
But since your GL context is always current on your rendering thread instead of the windowing system's main thread, your callbacks wouldn't access the GL object directly -- they'd pass a message to your rendering thread to do it for them.
Thank you for your response but I haven't been successful. I have verified that my setup is correct by getting SimpleScene found on the wiki to compile and run. When I try and render outside of the callback I get the following:
Exception in thread "main" javax.media.opengl.GLException: Unable to create temp OpenGL context for device context 0x6d0130a2
What I'm doing is the following (just the main ui thread for now):
GLProfile.initSingleton( true );
GLProfile glp = GLProfile.getDefault();
GLCapabilities caps = new GLCapabilities( glp );
GLCanvas canvas = new GLCanvas( caps );
I tried this myself, and I couldn't get it to work either. Without the canvas (which you can't access outside the main window thread), it seems like I can't make the context current correctly, so accessing it from another thread doesn't draw anything, and I just see a black screen. I tried in SWT and AWT, and couldn't make it work either way.
I guess calling your main rendering method from inside GLEventListener.display() is the way to go -- hopefully that won't require too much change to your app.
No problem. Thanks anyway. Since my BlackBerry and Android versions queue up work, I was able to make a JOGL version that consumes in the display callback instead of a thread. It wasn't as big of a change as I thought.