如何创建最大化的lwjgl窗口或以编程方式最大化已创建的显示?
注意:我不会询问如何为显示器设置全屏模式。
答案 0 :(得分:2)
Display.setResizable(真)
这将启用最大化按钮。
答案 1 :(得分:1)
我使用了网站上的LWJGL示例,它获取了可能的显示模式并将其设置为全屏最佳模式。只需创建另一个类并使用此代码!
public class DisplayConfig {
//This is the Class that lets us switch between full screen
//and window mode.
public void setDisplayMode(int width, int height, boolean fullscreen){
//If the display mode we are trying to achieve is already running
//we just jump straight back out.
if((Display.getDisplayMode().getWidth() == width) &&
(Display.getDisplayMode().getHeight() == height) &&
(Display.isFullscreen() == fullscreen)){
return;
}
try{
DisplayMode targetDisplayMode = null;
//if we are in full screen mode we will have to check and iterate
//through the computers available display modes to get back to
//where we started
if(fullscreen){
DisplayMode[] modes = Display.getAvailableDisplayModes();
int freq =0;
for (DisplayMode displayMode : modes) {
System.out.println(displayMode.getWidth()+" "+displayMode.getHeight());
}
for (int i = 0; i < modes.length; i++) {
DisplayMode current = modes[i];
if((current.getWidth() == width) && (current.getHeight() == height)){
if((targetDisplayMode == null) || (current.getFrequency() >= freq)){
if((targetDisplayMode == null) || (current.getBitsPerPixel() > targetDisplayMode.getBitsPerPixel())){
targetDisplayMode = current;
freq = targetDisplayMode.getFrequency();
}
}
if((current.getBitsPerPixel() == Display.getDesktopDisplayMode().getBitsPerPixel()) &&
(current.getFrequency() == Display.getDesktopDisplayMode().getFrequency())){
targetDisplayMode = current;
break;
}
}
}
} else {
targetDisplayMode = new DisplayMode(width, height);
}
if (targetDisplayMode == null){
System.out.println("Failed to find value mode: "+width+"x"+height+" fs="+fullscreen);
return;
}
Display.setDisplayMode(targetDisplayMode);
Display.setFullscreen(fullscreen);
} catch (LWJGLException e){
System.out.println("Unable to setup mode "+width+"x"+height+" fullscreen="+fullscreen + e);
}
}
}
http://lwjgl.org/wiki/index.php?title=LWJGL_Basics_5_(Fullscreen)
答案 2 :(得分:0)
Dimension screenDimensions = Toolkit.getDefaultToolkit().getScreenSize();
screenDimensions.width;
screenDimensions.height;
// this gets the height and width of your screen
// and
Display.setDisplayMode(new DisplayMode(screenDimensions.width, screenDimensions.height));