Creating a maximized lwjgl window

假如想象 提交于 2019-12-01 22:34:19

问题


How can i create a lwjgl window maximized or make an already created display maximized programmatically?

Note: im not asking how to set full-screen mode for the display.


回答1:


Display.setResizable(true)

this will enable the maximize button.




回答2:


I used the LWJGL sample from the website, it gets the possible displaymodes and set it to the best one in fullscreen. Just create anoother class and use this code!

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)




回答3:


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));


来源:https://stackoverflow.com/questions/15274707/creating-a-maximized-lwjgl-window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!