question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lwjgl3 : Gdx.graphics.setWindowedMode does not center the window

See original GitHub issue

Issue details

Create a game with the below code (notice that setWindowedMode(1920, 1280) must be different value than the one in the Lwjgl3ApplicationConfiguration), make sure you are using Lwjgl3 desktop.

Toggling btween windowed mode and fullscreen (press ENTER) does not center the window. LwjglGraphics does not update the window position according to the new size but leaves it at it’s current position. Maybe this is wanted (I don’t believe it is though), but then please give the users a possibilty to center the window manually.

Reproduction steps/code

Sorry, for some reason github messes up the code formatting…

public class DesktopLauncher { public static void main(String[] arg) { new Lwjgl3Application(new TCTest(), new Lwjgl3ApplicationConfiguration()); } }

` public class TCTest extends ApplicationAdapter { SpriteBatch batch; Texture img;

@Override
public void create() {
	batch = new SpriteBatch();
	img = new Texture("badlogic.jpg");
}

@Override
public void render() {
	if (com.badlogic.gdx.Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) {
		if (!Gdx.graphics.isFullscreen())
			Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
		else
			Gdx.graphics.setWindowedMode(1920, 1280); // Depending on your supported screen resolutions use other values
	}

	Gdx.gl.glClearColor(1, 0, 0, 1);
	Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
	batch.begin();
	batch.draw(img, 0, 0);
	batch.end();
}

@Override
public void dispose() {
	batch.dispose();
	img.dispose();
}

} `

Version of LibGDX and/or relevant dependencies

1.9.12-SNAPSHOT Lwjgl3 (it works fine with Lwjgl2)

Please select the affected platforms

  • Android
  • iOS (robovm)
  • HTML/GWT
  • Windows
  • Linux
  • MacOS

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
crykncommented, Sep 8, 2020

I agree that it is not expected when leaving fullscreen and returning to the previous window size. However, when changing from fullscreen to a windowed screen size different than before, I think this should be treated like normal resizing, i.e. re-centering the window again.

0reactions
TCreutzenbergcommented, Sep 9, 2020

I totally agree with @crykn

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to center window in LibGDX with LWJGL3 after resize
setWindowedMode (width, height) // Can use context size because of no decorations on window window.setWindowPos(Gdx.graphics.width/2 ...
Read more >
Going from fullscreen to windowed mode cause framerate to ...
When my game starts up in windowed mode or when it is in ... Monitor currentMonitor = Gdx.graphics. ... setWindowedMode(Gdx.graphics.
Read more >
Lwjgl3WindowConfiguration (libGDX LWJGL 3 Backend 1.9.8 ...
com.badlogic.gdx.backends.lwjgl3. ... Sets the icon that will be used in the window's title bar. ... public void setWindowedMode(int width, int height).
Read more >
com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window Java Exaples
private boolean fullscreenMode() { Lwjgl3Window window = ((Lwjgl3Graphics) Gdx.graphics).getWindow(); windowWidth = Gdx.graphics.
Read more >
Querying and configuring graphics (monitors, display modes ...
libGDX has an elaborate API that lets you query monitors and display ... To center your window, use -1 for the coordinates (the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found