I know there are threads about this topic but none of them solved my problem: My game written in Java should support JOGL in full screen exclusive mode.
All the game’s stuff is rendered in a GLCanvas living in a Frame. The game supports switching the GFX mode at runtime and this is how I have realized that initialization:
void init(String title) {
GLCapabilities glc = new GLCapabilities();
canvas = GLDrawableFactory.getFactory().createGLCanvas( glc, null, null, defaultGraphicsDevice);
// creates titled Frame for the game
frame = new Frame(title);
frame.setLayout(new GridLayout());
frame.add(canvas);
frame.addComponentListener(new ComponentAdapter() {
public void componentMoved(ComponentEvent ce) {
displayPrefs.updateWindowBounds(frame.getBounds());
}
});
// applies a valid size by restoring the former window bounds
frame.setBounds(displayPrefs.getWindowBounds());
// fs on Windows does not work due to problems with JOGL or the JDK. Don't know ...
isFullscreen = displayPrefs.isFullscreen() && System.getProperty("os.name").equals("Windows");
canvas.addGLEventListener(this);
if(isFullscreen) {
// remove Window decorations
frame.setUndecorated(true);
// switch to fullscreen mode
defaultGraphicsDevice.setFullScreenWindow(frame);
DisplayMode dm = displayPrefs.getDisplayMode();
// switch display mode if that is possible
if(defaultGraphicsDevice.isFullScreenSupported()) {
defaultGraphicsDevice.setDisplayMode(dm);
}
} else {
frame.setVisible(true);
}
canvas.setRenderingThread(Thread.currentThread());
}
(whenever reinitialization is necessary the frame is disposed beforehand)
The displayPrefs object knows the display mode and whether fullscreen is wanted by the user. I am not using JOGL’s Animator class because this would introduce an unneeded thread. That is why the rendering thread is set to the one executing the init method.
Now the problem: This code works fine in Linux (where Sun forget to support real FSEM - get private lessons from the LWJGL team …) but fails on Windows when setting the Frame as the default graphic device’s fullscreen window (fail means Exception that a surface could not be locked).
I have heard about placing the addGLEventListener to a point after making the frame visible but doing so did not help. Playing around with sun.java2d.noddraw did not help either.
Anybody out there seeing a problem in the code or wants to show use his/her working example?