*/
private static boolean initGraphics(final String title) {
int width = 1920;
int height = 1200;
try {
DisplayMode currentMode = Display.getDisplayMode();
log.fine("currentmode: " + currentMode.getWidth() + ", " + currentMode.getHeight() + ", " + currentMode.getBitsPerPixel() + ", " + currentMode.getFrequency());
width = currentMode.getWidth();
height = currentMode.getHeight();
// get available modes, and print out
DisplayMode[] modes = Display.getAvailableDisplayModes();
log.fine("Found " + modes.length + " display modes");
List < DisplayMode > matching = new ArrayList < DisplayMode >();
for (int i = 0; i < modes.length; i++) {
DisplayMode mode = modes[i];
if (mode.getWidth() == WIDTH && mode.getHeight() == HEIGHT && mode.getBitsPerPixel() == 32 ) {
log.fine(mode.getWidth() + ", " + mode.getHeight() + ", " + mode.getBitsPerPixel() + ", " + mode.getFrequency());
matching.add(mode);
}
}
DisplayMode[] matchingModes = matching.toArray(new DisplayMode[0]);
// find mode with matching freq
boolean found = false;
for (int i = 0; i < matchingModes.length; i++) {
if (matchingModes[i].getFrequency() == currentMode.getFrequency()) {
log.fine("using mode: " + matchingModes[i].getWidth() + ", "
+ matchingModes[i].getHeight() + ", "
+ matchingModes[i].getBitsPerPixel() + ", "
+ matchingModes[i].getFrequency());
Display.setDisplayMode(matchingModes[i]);
found = true;
break;
}
}
if (!found) {
Arrays.sort(matchingModes, new Comparator < DisplayMode >() {
public int compare(final DisplayMode o1, final DisplayMode o2) {
if (o1.getFrequency() > o2.getFrequency()) {
return 1;
} else if (o1.getFrequency() < o2.getFrequency()) {
return -1;
} else {
return 0;
}
}
});
for (DisplayMode mode : matchingModes) {
log.fine("using fallback mode: " + mode.getWidth() + ", "
+ mode.getHeight() + ", "
+ mode.getBitsPerPixel() + ", "
+ mode.getFrequency());
Display.setDisplayMode(mode);
break;
}
}