3
\$\begingroup\$

I have just started working with libgdx, and have run into my first problem. I have a simple program that switches a desktop application from windowed mode to fullscreen and back again. If I start the program in windowed mode, it initially displays fine. When I toggle to full screen it is also OK.

However, when I toggle back to windowed mode the screen goes completely black. The application remains responsive though, and if I toggle again it will go back to fullscreen and display correctly.

I am using 64-bit Windows 7 with the IntelliJ IDEA IDE.

Any help with working out why it is doing this would be greatly appreciated.

A minimal example that displays the issue is shown below:

public class MyGdxGame extends ApplicationAdapter {

    @Override
    public void create () {
        fullScreen = false;
    }

    @Override
    public void render () {
        Gdx.gl.glClearColor(1, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        if (Gdx.input.isKeyPressed(Input.Keys.TAB)) {
            fullScreen = !fullScreen;
            DisplayMode currentMode = Gdx.graphics.getDesktopDisplayMode();
            Gdx.graphics.setDisplayMode(currentMode.width, currentMode.height, fullScreen);
    }
}

private boolean fullScreen;
}
\$\endgroup\$
  • \$\begingroup\$ You probably won't want the same resolution for windowed and fullscreen modes. Anyway, your code seems fine, is the same non-expected result observed on this minimal example? (screen black instead of red) \$\endgroup\$ – Gustavo Maciel Jun 16 '14 at 0:00
  • \$\begingroup\$ Not worried about screen resolution yet - one step at a time =) I get the same problem with a black background instead of a red one \$\endgroup\$ – Wibbs Jun 16 '14 at 0:02
1
\$\begingroup\$

I've run into this problem on certain displays, while it had worked just fine on other displays.

My specific situation was a little different and was that I was trying to switch from 1280x1024 fullscreen to 800x600 windowed and the screen went black during the transition from fullscreen to windowed mode.

A borderless window configuration enveloping the whole screen had the exact same issue as well for me. (Transitioning from borderless fullscreen window to plain window mode)

The thing that worked for me was switching from fullscreen mode to another fullscreen mode but with the adjusted resolution, then immediately switching to the same resolution but without fullscreen enabled.

So in effect I called the setDisplayMode() method twice in succession.

i.e. (with hard coded values):

Gdx.graphics.setDisplayMode(800, 600, true);
Gdx.graphics.setDisplayMode(800, 600, false);

All in all it seems like a display-specific issue.

\$\endgroup\$
1
\$\begingroup\$
       Boolean fullScreen = Gdx.graphics.isFullscreen();
        Graphics.DisplayMode currentMode = Gdx.graphics.getDisplayMode();
        if (fullScreen == true)
            Gdx.graphics.setWindowedMode(currentMode.width, currentMode.height);
        else
            Gdx.graphics.setFullscreenMode(currentMode);
\$\endgroup\$
  • \$\begingroup\$ While a bloc of code helps, would you mind editing your post and explaining what is causing the issue of the OP and what your code does to fix it? \$\endgroup\$ – Vaillancourt Apr 14 '16 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.