Using GLCanvas in Visual IDE

I’m building a GLCanvas-based application in NetBeans 5.0, and when I place a GLCanvas on the visual editor, the editor no longer draws, due to the exception given below. Curiously, this does not happen for a GLJPanel… At any rate, does anyone know of a fix for how to prevent this? Or, for that matter, is there a way to tell the canvas to just not render or something (but still show its boundaries for the visual editor)? Now I can just set it to not visible, edit the rest of the GUI, and then set it to visible when I’m done, but that screws up the layout and everything, making it not quite as useful…

javax.media.opengl.GLException: Unable to lock surface
at com.sun.opengl.impl.windows.WindowsOnscreenGLDrawable.lockSurface(WindowsOnscreenGLDrawable.java:169)
at com.sun.opengl.impl.windows.WindowsOnscreenGLContext.makeCurrentImpl(WindowsOnscreenGLContext.java:57)
at com.sun.opengl.impl.GLContextImpl.makeCurrent(GLContextImpl.java:118)
at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:182)
at javax.media.opengl.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:258)
at javax.media.opengl.GLCanvas.display(GLCanvas.java:130)
at javax.media.opengl.GLCanvas.paint(GLCanvas.java:142)

… the rest down are about 20 or 30 regular swing and awt paint/graphics calls - I can’t copy/paste from that window, some I’m not going to transcribe the rest…

I suspect the Matisse editor is doing some pretty deep magic preventing JOGL from working properly. I think your best bet may be to just use a normal Canvas for your layout and replace it with a GLCanvas later.

That would work, but it’d be inconvinient for later expansion of the GUI… do you know of any way to simple tell the editor to not paint the GLCanvas (but still maintain all its properties and its location)?

Place a simple Canvas in the visual editor. Go to “Source” view and add


	private java.awt.Canvas createGLCanvas()
	{
		// create and return your GLCanvas here...
	}

Go back to “Design” view, select the Canvas and change to the “Code” section in it’s Properties dock. Enter “createGLCanvas();” as Custom Creation Code.

Ah, that seems to work well… but what’s the most efficient way to redisplay the GLCanvas after I’ve changed something? I was using GLCanvas.display() before, and I suppose I can always case the Canvas to a GLCanvas, but that raises my hackles as bad programming practice… will Canvas.repaint() work as efficiently?

Yes. Keep in mind that display() is guaranteed to be synchronous (i.e., not return until the drawing is complete) while repaint() is asynchronous.