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.