When running as an applet we have the following code to enter / exit full screen mode:
private void enterFullscreen() throws Exception {
DisplayMode mode = findDisplayMode(800, 600, Display.getDisplayMode().getBitsPerPixel());
int width = mode.getWidth();
int height = mode.getHeight();
Display.setDisplayModeAndFullscreen(mode);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, width, height, 0, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glTranslatef(0, 0, 0);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glViewport(0, 0, width, height);
Display.setVSyncEnabled(true);
}
private void enterWindowed() throws Exception {
int width = Applet.this.getWidth();
int height = Applet.this.getHeight();
DisplayMode mode = new DisplayMode(width, height);
Display.setDisplayModeAndFullscreen(mode);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, width, height, 0, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glTranslatef(0, 0, 0);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glViewport(0, 0, width, height);
Display.setVSyncEnabled(true);
}
private DisplayMode findDisplayMode(int width, int height, int bpp) throws LWJGLException {
DisplayMode[] modes = Display.getAvailableDisplayModes();
for ( DisplayMode mode : modes ) {
if ( mode.getWidth() == width && mode.getHeight() == height && mode.getBitsPerPixel() >= bpp && mode.getFrequency() <= 60 ) {
return mode;
}
}
return Display.getDesktopDisplayMode();
}
Entering / exiting works fine under Linux. On Mac however, it first spits out a few warnings:
2011-10-19 15:09:54.756 java[4100:903] *** Assertion failure in -[CocoaAppWindow _changeJustMain], /SourceCache/AppKit/AppKit-1038.36/AppKit.subproj/NSWindow.m:9470
2011-10-19 15:09:54.758 java[4100:903] *** CPerformer: ignoring exception 'Invalid parameter not satisfying: [self canBecomeMainWindow]' raised during perform of selector 'requestFocus:' on target 'FocusManager' with args '<AWTComponentSetFocusData: 0x109612040>'
2011-10-19 15:09:54.813 java[4100:10317] Make pbuffer: 800 x 600
2011-10-19 15:09:54.903 java[4100:903] invalid drawable
...
2011-10-19 15:10:25.472 java[4100:903] -[NSViewAWT pixelsWide]: unrecognized selector sent to instance 0x10016eee0
2011-10-19 15:10:25.473 java[4100:903] -[NSViewAWT pixelsWide]: unrecognized selector sent to instance 0x10016eee0
but everything keeps working until I exit full screen mode, then it crashes:
2011-10-19 15:10:38.241 java[4100:10317] -[NSViewAWT pixelsWide]: unrecognized selector sent to instance 0x10016eee0
2011-10-19 15:10:38.241 java[4100:10317] An uncaught exception was raised
2011-10-19 15:10:38.242 java[4100:10317] -[NSViewAWT pixelsWide]: unrecognized selector sent to instance 0x10016eee0
2011-10-19 15:10:38.305 java[4100:10317] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSViewAWT pixelsWide]: unrecognized selector sent to instance 0x10016eee0'
*** Call stack at first throw:
(
0 CoreFoundation 0x00007fff859cd7b4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x00007fff8a34ef03 objc_exception_throw + 45
2 CoreFoundation 0x00007fff85a27110 +[NSObject(NSObject) doesNotRecognizeSelector:] + 0
3 CoreFoundation 0x00007fff8599f91f ___forwarding___ + 751
4 CoreFoundation 0x00007fff8599ba68 _CF_forwarding_prep_0 + 232
5 liblwjgl.jnilib 0x000000011f3f409f Java_org_lwjgl_opengl_MacOSXCanvasPeerInfo_nInitHandle + 223
6 ??? 0x0000000102011d6e 0x0 + 4328594798
7 ??? 0x000000010200685a 0x0 + 4328548442
)
terminate called after throwing an instance of 'NSException'
Process finished with exit code 134
It seems there is something fishy going on when reinitializing the CanvasPeerInfo in the Mac OS X native code. I don't do Objective C too much, but my interpretation is that the peer_info->pbuffer is pointing to an NSViewAWT...? Here's how we set up the AWT canvas in the first place, we're using Slick2D with slight modifications:
public class FooApplet extends Applet {
...
public void init() {
removeAll();
setIgnoreRepaint(true);
displayParent = new Canvas() {
public final void addNotify() {
super.addNotify();
Display.setParent(displayParent);
Display.setVSyncEnabled(true);
Display.create(new PixelFormat(8,8,0));
initGL();
displayParent.requestFocus();
container.runloop();
}
};
displayParent.setSize(getWidth(), getHeight());
add(displayParent);
displayParent.setFocusable(true);
displayParent.requestFocus();
displayParent.setIgnoreRepaint(true);
setVisible(true);
}
I also compared my code to the LWJGL FullScreenWindowedTest.java, which works without problems on Mac. I can't find anything obvious that I'm doing different except for the AWT stuff of course.
Please excuse me if I'm the one doing something wrong here
Any help appreciated.