Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm working on a libGDX (library on top of LWJGL) game project, and use the Intellij IDEA IDE from several different workstations:

  • Windows 7 x64 laptop with two displays (1920x1080 and 1600x1200), nVidia GT540M.
  • Ubuntu 12.04 LTS on a laptop with a single display (1366x768), Intel integrated graphics.
  • Ubuntu 12.04 LTS on a desktop with two displays (1920x1080 and 1280x1024), nVidia GTS 450.

I'm using the OpenJDK for Java 6 on the Ubuntu boxes, and Sun/Oracle Java 6 on the Windows box (I heard Java 6 was the one to use for Android compatibility).

When running on full-screen:

  • Windows 7 laptop: works fine.
  • Ubuntu laptop: works fine.
  • Ubuntu desktop: background image is shown enlarged, and only part of it fits on the screen. +

Looking into this further, I see that the calls to Gdx.graphics.getHeight() and Gdx.graphics.getWidth() return the size of the rectangle needed to cover both displays, in my case 3200x1080, but when I tell my game to run full-screen, it only uses one of the displays, so the cameras get set to 1920x1080, but my camera movement and Tiled map panning think they've got 3200x1080 to work with, making things distorted and unusable (since character can walk off of the screen to the right).

I'm guessing my problem actually comes from the sizes returned by the awt.Toolkit's getScreenSize() call, but I don't know how to interrogate it more deeply to get the size of the screen it will actually use when I go fullscreen.

My DesktopStarter gets the screen size and sets fullscreen as follows:

    LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();     Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();     cfg.width = screenDimension.width;     cfg.height = screenDimension.height;     cfg.fullscreen = true;     new LwjglApplication(new Game1(), cfg); 

Is there a work-around to get the height/width of just the display that "full screen" will actually launch into?

So the trouble I'm seeing, is that executing the game.jar file, exiting the game, then executing again, repeatedly, results in different display modes showing up in the list of modes returned by Gdx.graphics.getDisplayModes() -- as P.T. pointed out below, this is a thin wrapper around LWJGL's Display.getAvailableDisplayModes(). Why is this happening? Why would it be a different set of modes presented on subsequent runs on Ubuntu?

edit: per P.T.'s suggestion, put LWJGL references in question, since it seems to be LWJGL that's providing the list of display modes.

Thanks!

like image 665
Shad Avatar asked May 09 '13 01:05

Shad


2 Answers

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.

like image 160
cfstras Avatar answered Sep 19 '22 17:09

cfstras


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()); } 
like image 35
johnny Avatar answered Sep 21 '22 17:09

johnny