Hi,
I’m using the Netbeans OpenGL pack, which is wonderful. But I am having two issues.
- My previous code (for JOGL 1.1.1) to toggle between fullscreen and back isn’t working. Instead the animator seems to freeze and the application hangs.
Here’s the logic that used to work:
- create a new frame
- create a new canvas with the same capabilities & context of the old canvas
- add the new canvas to the new frame
- display the new frame (ie as full screen or in a window)
- display the canvas
- dispose the old frame
- create a new Animator for the new canvas and start it.
JFrame tmpFrame = new JFrame(appName);
GLCanvas tmpCanvas = new GLCanvas(
canvas.getChosenGLCapabilities(),
new DefaultGLCapabilitiesChooser(),
canvas.getContext(),
null);
tmpFrame.add(tmpCanvas);
tmpFrame.setUndecorated(true);
device.setFullScreenWindow(tmpFrame);
tmpCanvas.display();
frame.dispose();
frame = tmpFrame;
canvas = tmpCanvas;
animator = new Animator(canvas);
animator.start();
This was working, although it did seem a bit convoluted. Any ideas on how to do a fullscreen toggle in JOGL2?
- The default JOGL2 project for the Netbeans OpenGL pack has this code:
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
// exiting
new Thread(new Runnable() {
public void run() {
animator.stop();
System.exit(0);
}
}).start();
}
});
But as far as I can tell, the display loop immediately exits upon receiving a windowClosing event, even if no windowListener is attached to the Frame. That is, the animator seems to automatically stop by itself and the GLEventListener dispose method gets automatically called. Just wanted to point this out because my shutdown hooks weren’t working and it took me a while to figure out what was going on. The GLContext is still active in the dispose method and resources can be flushed properly, etc.
In other words, I think the code above can be replaced with
public void dispose(GLAutoDrawable arg0) {
System.exit(0);
}
-sj