Here’s an actual example of getting the right display mode, lifted straight from Alien Flux’s init code:
if (!AL.isCreated()) {
try {
AL.create();
soundPlayer = new SoundPlayer(16);
} catch (Exception e) {
e.printStackTrace();
Sys.alert(
GAME_TITLE,
"You need an OpenAL compatible sound card to to hear the sound effects and music in "
+ GAME_TITLE
+ ". You may have a suitable card but not have appropriate drivers. Please contact "
+ EMAIL_ADDRESS
+ " for assistance if you need help finding drivers for your sound card.");
}
}
if (!WINDOWED) {
try {
// Filter out modes smaller than 640x480, but anything bigger will do. We also pick frequencies between
// 60Hz and 85Hz as sometimes display drivers like to give us dodgy values which can blow up monitors.
// We don't care what colour depth it gives us.
DisplayMode[] dm = Display.getAvailableDisplayModes(640, 480, -1, -1, -1, -1, 60, 85);
Display.setDisplayMode(dm, new String[] {
"width="+options.getPreferredWidth(), // Will pick the preferred width, otherwise the nearest it can
"height="+options.getPreferredHeight(), // Will pick the preffered height, otherwise the nearest it can
"freq="+PREFERRED_FREQUENCY, // Will pick 60Hz over any other frequency, and otherwise pick the fastest it can
"bpp=" + (options.isTrueColour() ? "32" : "16"), // Pick 16 or 32 bit over any other depth, otherwise the nearest it can
});
} catch (Exception e) {
e.printStackTrace();
}
}
try {
Window window;
if (WINDOWED) {
width = java.lang.Math.min(org.lwjgl.Display.getWidth(), WINDOW_WIDTH);
height = java.lang.Math.min(org.lwjgl.Display.getHeight(), WINDOW_HEIGHT);
Window.create(GAME_TITLE, 0, 0, width, height, 16, 0, 0, 0);
} else {
width = org.lwjgl.Display.getWidth();
height = org.lwjgl.Display.getHeight();
try {
Window.create(GAME_TITLE, 16, 0, 0, 0);
} catch (Exception e) {
width = java.lang.Math.min(org.lwjgl.Display.getWidth(), WINDOW_WIDTH);
height = java.lang.Math.min(org.lwjgl.Display.getHeight(), WINDOW_HEIGHT);
Window.create(GAME_TITLE, 0, 0, width, height, 16, 0, 0, 0);
}
}
GLCaps.determineAvailableExtensions();
} catch (Exception e) {
e.printStackTrace();
cleanup();
Sys.alert(
GAME_TITLE,
"You need an OpenGL compatible graphics card to run "
+ GAME_TITLE
+ ". You may have a suitable graphics card but not have OpenGL drivers. Please contact "
+ EMAIL_ADDRESS
+ " for assistance if you need help finding OpenGL drivers for your graphics card.");
System.exit(0);
}
try {
Keyboard.create();
try {
Keyboard.enableBuffer();
try {
Keyboard.enableTranslation();
} catch (Exception e) {
System.out.println("Failed to enable translation:"+e);
}
} catch (Exception e) {
System.out.println("Failed to enable keyboard buffer:"+e);
}
} catch (Exception e) {
System.out.println("Failed to create keyboard:"+e);
}
try {
Mouse.create();
} catch (Exception e) {
System.out.println("Failed to create mouse:"+e);
}
try {
Controller.create();
} catch (Exception e) {
System.out.println("Failed to create controller:"+e);
}
// Sync to vertical blank if we can to smooth things out a bit
if (GLCaps.WGL_EXT_swap_control && org.lwjgl.Display.getFrequency() == PREFERRED_FREQUENCY && !Sys.DEBUG) {
GL.wglSwapIntervalEXT(1);
} else {
// Turn off swap control if we can't get 60Hz display
GLCaps.WGL_EXT_swap_control = false;
}
Cas 