我在使我的程序全屏显示时遇到问题:
Display.setFullscreen(true);
...但以下答案帮助了我:LWJGL Fullscreen not working
这个答案建议我遍历所有可用的 DisplayModes 并找到兼容的。这是我目前拥有的代码:
if (!fullscreen)
Display.setDisplayMode(new DisplayMode(width, height));
else {
DisplayMode displayMode = null;
DisplayMode[] modes = Display.getAvailableDisplayModes();
ArrayList<String> compatibleModes = new ArrayList<String>();
for (int i = 0; i < modes.length; i++) {
System.out.println("Mode "+i+": "+modes[i].toString());
if (modes[i].getWidth() == width && modes[i].getHeight() == height
&& modes[i].isFullscreenCapable()) {
displayMode = modes[i];
compatibleModes.add(modes[i].toString());
}
}
if(compatibleModes.isEmpty()){
System.out.println("No compatible display modes!");
System.exit(-1);
}
System.out.println("Display Modes :: "+modes.length+" Total :: "+compatibleModes.size()+" Compatible :: "+displayMode.toString()+" Selected");
for (String string : compatibleModes) {
System.out.println("Compatible: "+string);
}
Display.setDisplayMode(displayMode);
Display.setFullscreen(true);
}
Display.create(new PixelFormat(), attribs);
我的控制台日志显示:(为了清楚起见,我省略了一些不相关的模式)
Mode 0: 1920 x 1080 x 32 @24Hz
Mode 5: 1920 x 1080 x 32 @23Hz
Mode 18: 1280 x 1024 x 32 @60Hz
Mode 19: 1920 x 1080 x 32 @59Hz
Mode 20: 1920 x 1080 x 32 @60Hz
Mode 21: 1920 x 1080 x 32 @50Hz
Mode 23: 1920 x 1200 x 32 @59Hz
Mode 25: 1920 x 1200 x 32 @60Hz
Mode 26: 1768 x 992 x 32 @24Hz
Mode 28: 1920 x 1440 x 32 @59Hz
Mode 29: 2560 x 1440 x 32 @59Hz <-- I have a 1440p monitor, why is this NOT compatible?
Mode 30: 1280 x 800 x 32 @60Hz
Mode 31: 1920 x 1440 x 32 @60Hz
Mode 49: 1600 x 1200 x 32 @59Hz
Mode 50: 1600 x 1200 x 32 @60Hz
Display Modes :: 53 Total :: 3 Compatible :: 1280 x 720 x 32 @60Hz Selected
Compatible: 1280 x 720 x 32 @50Hz
Compatible: 1280 x 720 x 32 @59Hz
Compatible: 1280 x 720 x 32 @60Hz
全屏游戏可以在我的电脑上以 1440p 正常运行,所以我不确定为什么该模式不可用。当我启动程序时,屏幕非常模糊。
我怎样才能解决这个问题?先感谢您。