Printing offscreen

As part of a larger project I’m trying to implement a facility that will export 3D renderings to bitmap formats. We do this by creating a GLJPanel and drawing the scene we want to it, then extracting the bitmap. This all works fine as long as the system has at least one visible window on the screen - not necessarily the window containing the panel we are drawing to.

But if we try to do this without making any window visible the GLJPanel won’t draw. Stepping through the JOGL source I find that it won’t draw unless it has a valid peer - essentially unless addNotify() has been called on it. The documentation says that addNotify() is only called when the panel is made part of a visible window heirarchy. Changing to a GLCanvas doesn’t make much difference - the failure mode is different. WindowsOnscreenGLDrawable.realized is not set, and this means lockSurface returns LOCK_SURFACE_NOT_READY, causing makeCurrent() to fail.

Any help would be welcome on how to create a Java app that can create and export 3D scenes without having to make it’s window visible.

You want to use a GLPBuffer. It’s an offscreen context that should do what you want. I believe they’re created by a GLDrawableFactory instead of a constructor. Also, not all graphics cards support them (most should nowadays), so it’s best to check if they’re supported first.

Thanks ihkbob.

GLPbuffer seems to have done the trick.

Google turned up this article http://today.java.net/pub/a/today/2008/10/30/integrating-glpbuffer-and-graphics2d.html which gave easy instructions on how to use it.