Reputation: 457
I'm creating a game with JOGL and I've come across an error which I can't for the life of me figure out.
In the game I'm using two GLCanvases (GLJpanels actually), one for the menu and one for the actual game. The idea being that when a game is started from the menu, the menu GLCanvas is removed from the gamewindow and swapped for the game GLCanvas. So far I've gotten the menu to work pretty much perfectly, but whenever I attempt to switch over to the game canvas, I get this error:
Catched Exception on thread AWT-EventQueue-0
javax.media.opengl.GLException: AWT-EventQueue-0: Context not current on thread, obj 0x2ab44e2d, ctx 0x0, surf 0x0, inDestruction: false, <53f7c06e, 2e7aa0d3>[count 0, qsz 0, owner <NULL>]
The code I'm using to switch between canvases is:
public void start()
{
canvas.addGLEventListener(this);
animator.start();
window.add(canvas);
canvas.requestFocus();
}
public void stop()
{
window.remove(canvas);
animator.stop();
canvas.removeGLEventListener(this);
}
and the switch function:
public void switchToCanvas(String canvasName)
{
currentCanvas = canvasName;
if(canvasName.equals("GameCanvas"))
{
menu.stop();
game.start();
}
else
{
game.stop();
menu.start();
}
}
I've done some googling and I came around this question: How can I create my own openGL context and bind it to a GLCanvas?
But none of the solution posted there worked for me.
Upvotes: 0
Views: 2539
Reputation: 4066
At first, I would rather use a single GLCanvas instead of 2 instances of GLJPanel. GLJPanel has an higher memory footprint and should only be used when GLWindow or AWT/SWT GLCanvas can't be used, when there are some issues with mixing heavyweight and lightweight components.
Secondly, your error message means that there is no OpenGL context current on this thread. You should use GLAutoDrawable.invoke() to put OpenGL tasks into the queue or you should make the context current when you need it. I advise you to look at jogl-demos to see how we do that in our examples.
Edit.: JogAmp maintainers including me can be easily contacted on the official forum (http://forum.jogamp.org/) and on IRC.
Upvotes: 1