10

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.

xjcl
  • 12,848
  • 6
  • 67
  • 89
enderbender
  • 145
  • 1
  • 1
  • 7

3 Answers3

18

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);
desertkun
  • 1,027
  • 10
  • 19
  • In Windows 10 it does not work, it shows a small window. – Lim Thye Chean Aug 21 '15 at 01:24
  • @LimThyeChean, works in 1.6.0 for Windows 10 as well. – desertkun Aug 21 '15 at 14:14
  • 6
    I am using 1.6.4, and this does not work on my Windows 10. Using this works: config.width = LwjglApplicationConfiguration.getDesktopDisplayMode().width; config.height = LwjglApplicationConfiguration.getDesktopDisplayMode().height; – Lim Thye Chean Aug 22 '15 at 10:27
  • Thanks Lim Thye Chean, It works in my windows 8.1 also – salih kallai Oct 28 '15 at 10:02
  • This works, but it's useless without knowing native screen resolution. Why should I fix screen resolution to 1024 x 678 if somebody is using FHD screen? How can I get native screen resolution at that point? – MilanG May 21 '16 at 13:55
  • Why did you specify a width and height when the desktop is fullscreen? – Shikhar Mainalee Apr 07 '19 at 00:05
  • @ShikharMainalee you actually have to specify resolution even in the fullscreen mode, so you can get more or less detail. You obviously cannot specify more than your display can provide, but you can specify less, so you'll get less resolution but gain in performance. – desertkun Apr 10 '19 at 11:09
7

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
);
bytestorm
  • 1,411
  • 3
  • 20
  • 36
  • Sadly, `setDisplayMode` method isn't available anymore. – Winter Feb 22 '17 at 19:01
  • So what is the alternative now? I can't figure it out. – GregorMohorko Feb 26 '17 at 13:41
  • 2
    Now there is [setFullScreenMode(Graphics.DisplayMode displayMode)](https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Graphics.html#setFullscreenMode-com.badlogic.gdx.Graphics.DisplayMode-) – vdlmrc Mar 05 '17 at 17:45
2

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.

xjcl
  • 12,848
  • 6
  • 67
  • 89