Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

opengl

lwjgl

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.

like image 436
Joehot200 Avatar asked Nov 06 '14 00:11

Joehot200


3 Answers

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

like image 185
jbutler483 Avatar answered Oct 23 '22 15:10

jbutler483


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.

like image 3
Dawnkeeper Avatar answered Oct 23 '22 16:10

Dawnkeeper


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);
like image 1
Alex - GlassEditor.com Avatar answered Oct 23 '22 15:10

Alex - GlassEditor.com