Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make LibGDX Desktop go fullscreen by default

I was wondering how to make my desktop app go fullscreen upon start-up. I am new to LibGDX and any help is greatly appreciated. Thank you.

like image 416
enderbender Avatar asked Dec 26 '13 12:12

enderbender


3 Answers

To set the game to full screen when the user presses F, and set to windowed on G (in Kotlin):

    override fun render() {
        ...
        if (Gdx.input.isKeyPressed(Input.Keys.F))
            Gdx.graphics.setFullscreenMode(Gdx.graphics.displayMode)
        if (Gdx.input.isKeyPressed(Input.Keys.G))
            Gdx.graphics.setWindowedMode(1280, 720)
        ...
    }

I'll change my answer to Java later and I'll add a way to toggle it.

like image 144
xjcl Avatar answered Oct 21 '22 20:10

xjcl


Just define fullscreen field in your LwjglApplicationConfiguration:

LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();

cfg.title = "yourGame";
cfg.width = 1024;
cfg.height = 768;
cfg.fullscreen = true;

new LwjglApplication(new ...(), cfg);
like image 18
desertkun Avatar answered Oct 21 '22 19:10

desertkun


To start your game with fullscreen mode set the following flags in LwjglApplicationConfiguration in your Desktop launcher (the main() function)

public static void main(String[] args) {
    LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
    cfg.width = 1280;
    cfg.height = 720;

    // fullscreen
    cfg.fullscreen = true;
    // vSync
    cfg.vSyncEnabled = true;

    new LwjglApplication(new YourApplicationListener(), cfg);
}

And if you want to enable full screen at any resolution or the desktop's default from an in-game option use

// set resolution to HD ready (1280 x 720) and set full-screen to true
Gdx.graphics.setDisplayMode(1280, 720, true);

// set resolution to default and set full-screen to true
Gdx.graphics.setDisplayMode(
              Gdx.graphics.getDesktopDisplayMode().width,
              Gdx.graphics.getDesktopDisplayMode().height, 
              true
);
like image 7
bytestorm Avatar answered Oct 21 '22 20:10

bytestorm