简体   繁体   English

如何将OpenGL显示(由OpenGL创建的窗口)设置为最大化?

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

I would like to set my OpenGL display to maximised. 我想将我的OpenGL显示设置为最大化。

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. 如果我使用setResizeable(true) ,我可以让用户手动执行,然后让玩家点击最大化按钮,这对于测试人员来说是一个痛苦而且是用户不必要的步骤。

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 . 如果您不理解全屏和最大化之间的区别( Meta Stack Overflow讨论 ),那么这里是Maximized的描述,这里是Fullscreen的描述。

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 . 调用CreateWindow或CreateWindowEx时,请使用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. 如果您正在使用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. 我认为您可以通过将Display位置设置为0px,0px并通过Display.getDesktopDisplayMode()获取桌面DisplayMode然后将此DisplayMode设置为新的DisplayMode来最大化窗口。

Full Screen Mode: 全屏模式:

setDisplayModeAndFullscreen 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. 如果没有通过create()创建上下文,则在调用create()时将应用该模式。
  • If mode.isFullscreenCapable() is true , the context will become a fullscreen context and the display mode is switched to the mode given by getDisplayMode() . 如果mode.isFullscreenCapable()true ,则上下文将成为全屏上下文,并且显示模式将切换为getDisplayMode()给出的模式。
  • If mode.isFullscreenCapable() is false , the context will become a windowed context with the dimensions given in the mode returned by getDisplayMode(). 如果mode.isFullscreenCapable()false ,则上下文将成为窗口化上下文,其中包含getDisplayMode().返回的模式中的维度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 我还发现 似乎是在提供一个可能的屏幕模式的数组列表 - 但我不确定

You can change the size of the LWJGL window using Display.setDisplayModeAndFullscreen(DisplayMode mode) as already mentioned by jbutler483. 您可以使用Display.setDisplayModeAndFullscreen(DisplayMode mode)更改LWJGL窗口的大小,如jbutler483所述。

But there is a trick to it. 但它有一个技巧。 There are three ways to get these Display modes: 有三种方法可以获得这些显示模式:

If you use the constructor you can tailor the mode to your liking, but these modes are all set to 'isFullscreenCapable() == false'. 如果您使用构造函数,您可以根据自己的喜好定制模式,但这些模式都设置为'isFullscreenCapable()== false'。

If you want to go fullscreen you have to use 'getAvailableDisplayModes()'and pick one that has 'isFullscreenCapable() == true'. 如果你想要全屏,你必须使用'getAvailableDisplayModes()'并选择一个'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. 最后但并非最不重要的是,你可以使用'getDesktopDisplayMode'来获得适合桌面的模式。 I never tested if this can have fullscreen enabled. 我从未测试过这是否可以启用全屏。

Set the parent of the display to a Canvas attached to a JFrame , and then set that JFrame to be maximised. 将显示的父级设置为附加到JFrameCanvas ,然后将该JFrame设置为最大化。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM