java and libGDX / LWJGL game fullscreen wrong size for multiple monitors on Ubuntu

时光怂恿深爱的人放手 提交于 2019-12-04 22:13:56

I would refrain from using Toolkit.getDefaultToolkit() and use solely lwjgl.util.Display.getAvailableDisplayModes() or the method described by libgdx.

Once you have set up a fullscreen window, fetch its size (if your set-up method doesn't already know that) and only use this information from thereon.

If Display.getAvailableDisplayModes() changes its sort order on different executions, simply re-sort them and use the biggest one available or use a standard one and provide in-game settings to change them.

GraphicsDevice monitors[]=GraphicsEnvironment.getScreenDevices(); 

Dimension screen_resolution[monitors.length];

for (int monitorID = 0; monitorID < monitors.length; monitorID++)
{
    screen_resolution[monitorID] = new Dimension(monitors[monitorID].getDisplyMode().getWidth(),monitors[monitorID].getDisplyMode().getHeight());
}

You could use javafx.stage.screen to work around this issue, but you'd either have to add JavaFX if you stick with Java 6, or upgrade to Java 7 (It's included with the Java 7 SDK.)

From the documentation:

"Describes the characteristics of a graphics destination such as monitor. In a virtual device multi-screen environment in which the desktop area could span multiple physical screen devices, the bounds of the Screen objects are relative to the Screen.primary.

For example:

Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();

//set Stage boundaries to visible bounds of the main screen stage.setX(primaryScreenBounds.getMinX()); stage.setY(primaryScreenBounds.getMinY()); stage.setWidth(primaryScreenBounds.getWidth()); stage.setHeight(primaryScreenBounds.getHeight());

stage.show();"

There are a variety of other methods (getBounds(), getDpi(), getScreens(), etc.) that would also likely be very useful for you.

Maybe get the dimensions of the monitor your currently using, so on the different sized monitors, just get the dimensions. You may have to do things differently for different sized monitors.

Maybe the background image is enlarged due to it thinking it's still working on the other screens.

Hope this helps, if not gl

I would refrain from using lwjgl completely. It may seem simple enough on the surface, but as you try to add in more advanced features, you'll realize that a wrapper over OpenGL won't give you that functionality, or it'll make the program 3x slower. I suggest moving into c++ and OpenGL (if this is an option). You will be surprised at its simplicity. Otherwise, cross-platform libraries generally do have these sorts of glitches. To solve your problem, you need to stop relying on the library to determine your viewport resolutions. Instead, enumerate through all the possible display modes and pick the best one according to you. This will result in much more defined behavior and will be easier to debug than utilizing a default config which appears as if by magic. In general, you want to always be sure you know what data you are using. Even worse, I just noticed that you are using a wrapper over a wrapper. This over-complicates and will slow down rendering much more that you can imagine (20x on average).

Here

http://www.lwjgl.org/wiki/index.php?title=LWJGL_Basics_5_%28Fullscreen%29

you will find a convenience method for lwjgl to chose a suitable full screen display mode for your desktop. You can use the same method to determine the resolution as well and use it for your gl ops later.

Toy Box Software

I am not sure but it worked for me. Just set the size after "start" the game, like in the following code:

public static void main(String[] args) {
    LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
    cfg.title = "Palmeiras!!";
    cfg.vSyncEnabled = false;
    cfg.forceExit = true;
    cfg.allowSoftwareMode = true;
    new LwjglApplication(new Palmeiras(null), cfg);

    Gdx.graphics.setDisplayMode(Gdx.graphics.getDesktopDisplayMode().width,
            Gdx.graphics.getDesktopDisplayMode().height, true);
}

Let me know if it worked for you.

I would refrain from using Toolkit.getDefaultToolkit() and use solely lwjgl.util.Display.getAvailableDisplayModes() or the method described by libgdx.

Once you have set up a fullscreen window, fetch its size (if your set-up method doesn't already know that) and only use this information from thereon.

If Display.getAvailableDisplayModes() changes its sort order on different executions, simply re-sort them and use the biggest one available or use a standard one and provide in-game settings to change them.

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