LibGDX DesktopLauncher set resolution to DesktopDisplayMode

Hey, so I wanted my application’s width and height defined in the DesktopLauncher class to be set to the user’s maximum screen resolution. I thought this would work:


config.width = LwjglApplicationConfiguration.getDesktopDisplayMode().width;
config.height = LwjglApplicationConfiguration.getDesktopDisplayMode().height;

However, this causes some weird behavior. The width and height aren’t set at all and all modifications to config after those two lines are completely ignored.

In your LibGDX projects, how do you normally set config.width and config.height in your DesktopLauncher class? How can I get it to default to the maximum resolution of the user’s monitor?

(I don’t want my window resizable so I want the window to completely take up their screen already in case you were wondering why I don’t just set it to 800x600 or something and let the user resize it)

Did you check what values LwjglApplicationConfiguration.getDesktopDisplayMode() returns?

This is how I do it.



public class DesktopLauncher {
	public static void main (String[] arg) {
		LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
		
		config.setFromDisplayMode(LwjglApplicationConfiguration.getDesktopDisplayMode());
		//If I want to test windowed
		boolean fullscreen = false;
		if(!fullscreen ){
			config.fullscreen = false;
			config.width /= 1.2f;
			config.height /= 1.2f;
		}
		config.resizable = false;
		config.samples = 4;		
		config.vSyncEnabled = true;
		
		new LwjglApplication(new CoreGame(), config);
	}
}

PD:Try to use the autocomplete feature to see whats avaible for you.

Hey thanks man, this works great. I wonder why it doesn’t like my way of doing it though.

@trollwarrior1 I did test it and it returned my native resolution, 1920x1080, so I thought it would work… oh well.