How can I set an OpenGL display (Window created by OpenGL) to maximized?

◇◆丶佛笑我妖孽 提交于 2019-12-23 13:27:11

问题


I would like to set my OpenGL display to maximised.

I can have users do it manually if I setResizeable(true) and then get players to click the maximise button, which as a tester mentioned is a pain and an unnecessary step for users.

I can set the display size to the same size as the players' screen, but that just looks odd, and I am not looking for fullscreen mode.

Obviously I can fullscreen and set display size already, but I am currently unable to find any method that actually allows me to actually maximise the display.

If you don't understand the difference between fullscreen and maximized (Meta Stack Overflow discussion), then here is a description of Maximized, and here is a description of Fullscreen.


回答1:


Set the parent of the display to a Canvas attached to a JFrame, and then set that JFrame to be maximised.

Example:

JFrame frame = new JFrame();
Canvas canvas = new Canvas();
frame.add(canvas);
frame.setVisible(true);
try {
    Display.setParent(canvas);
    Display.create();
} catch (LWJGLException e) {
    e.printStackTrace();
}
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);



回答2:


this is too long to be a comment, so i'll primarily post it here:

Maximised Mode:

when calling CreateWindow or CreateWindowEx, use WS_MAZIMIZE.

 hwnd = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "The title of my window",
        WS_MAZIMIZE,
        CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
        NULL, NULL, hInstance, NULL);

This thread may be of interest if you are using GLUT.

A suggestion here was to

I think you can maximize the window by setting the Display location to 0px,0px and getting the desktop DisplayMode via Display.getDesktopDisplayMode() and then setting this DisplayMode as new DisplayMode.

Full Screen Mode:

setDisplayModeAndFullscreen

public static void setDisplayModeAndFullscreen(DisplayMode mode)
                                        throws LWJGLException
  • Set the mode of the context.
  • If no context has been created through create(), the mode will apply when create() is called.
  • If mode.isFullscreenCapable() is true, the context will become a fullscreen context and the display mode is switched to the mode given by getDisplayMode().
  • If mode.isFullscreenCapable() is false, the context will become a windowed context with the dimensions given in the mode returned by getDisplayMode(). The native cursor position is also reset.

Parameters:

mode - The new display mode to set. Must be non-null.
Throws:
LWJGLException - If the mode switch fails.

Found here.

I also found this which seems to be filing an array list with possible screen modes - but I'm not certain




回答3:


You can change the size of the LWJGL window using Display.setDisplayModeAndFullscreen(DisplayMode mode) as already mentioned by jbutler483.

But there is a trick to it. There are three ways to get these Display modes:

  • 'new DisplayMode(width,height)'
  • 'Desktop.getDesktopDisplayMode()'
  • 'Desktop.getAvailableDisplayModes()'

If you use the constructor you can tailor the mode to your liking, but these modes are all set to 'isFullscreenCapable() == false'.

If you want to go fullscreen you have to use 'getAvailableDisplayModes()'and pick one that has 'isFullscreenCapable() == true'. This is the only way to obtain a fullscreen mode.

And last but not least you can use 'getDesktopDisplayMode' to get a mode that fits the Desktop. I never tested if this can have fullscreen enabled.



来源:https://stackoverflow.com/questions/26769496/how-can-i-set-an-opengl-display-window-created-by-opengl-to-maximized

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