4

如何以编程方式创建最大化的 lwjgl 窗口或使已创建的显示最大化?

注意:我没有问如何为显示器设置全屏模式。

4

3 回答 3

2

Display.setResizable(true)

this will enable the maximize button.

于 2013-08-29T18:48:06.690 回答
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_(全屏)

于 2014-08-31T20:56:44.897 回答
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));
于 2013-03-14T03:16:05.983 回答