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.

Add support for borderless fullscreen mode on supporting desktop OSes

See original GitHub issue

Issue details

On desktop, libGDX currently offers windowed mode and fullscreen mode. There is a special third option, typically called borderless fullscreen, whereby a window with the exact characteristics of the monitor’s display mode is created. There are two main advantages to this. One is smoother switching between the ‘fullscreen’ window and other programs (no black flickering due to display mode changes). The other is that it prevents the ‘fullscreen’ window from being iconified when focusing on another window on a different monitor, which is what happens when using the traditional fullscreen mode with autoIconify set to true.

For Windows (only tested on Windows 10), one can activate borderless fullscreen as follows:

public static void setBorderlessFullscreenMode(Graphics.Monitor monitor) {
    var window = ((Lwjgl3Graphics) Gdx.graphics).getWindow();
    var mode = (Lwjgl3Graphics.Lwjgl3DisplayMode) Gdx.graphics.getDisplayMode(monitor);
    GLFW.glfwSetWindowMonitor(window.getWindowHandle(), 0, 0, 0, mode.width, mode.height, mode.refreshRate);
}

The functionality is documented here: https://www.glfw.org/docs/latest/window_guide.html#window_windowed_full_screen What is not mentioned, however, is that one needs to set the monitor parameter to 0 for this to work (see https://github.com/glfw/glfw/issues/1267).

I think it would be great for this to be added as a method in Gdx.graphics.

Someone should test whether this also works on macOS and Linux.

Version of libGDX and/or relevant dependencies

libGDX 1.10.0 with LWJGL3 backend

Please select the affected platforms

  • Android
  • iOS
  • HTML/GWT
  • Windows
  • Linux
  • MacOS

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
crykncommented, Sep 13, 2021

Ah nice, that is good to know! I have opened a PR (#6649) to fix the issues mentioned in my comment above. After it is merged (reviews are welcome!), borderless fullscreen can be achieved as follows:

Gdx.graphics.setUndecorated(true);
Graphics.DisplayMode displayMode = Gdx.graphics.getDisplayMode();
Gdx.graphics.setWindowedMode(displayMode.width, displayMode.height);

Or, if you want to use the ‘1 pixel wider’ trick, the last line has to be change to Gdx.graphics.setWindowedMode(displayMode.width, displayMode.height + 1);.

1reaction
MontyHimselfcommented, Sep 13, 2021

Thanks @crykn for the thorough testing!

I did some more research and figured out that the flickering for undecorated windows is apparently due to OpenGL not having the same control over the swapchain as DirectX. See here: https://discourse.glfw.org/t/cannot-manage-to-create-borderless-windowed-form/1592/2

The workaround described in that discussion is to add one pixel to the resolution of the window. Lo and behold, the flickering disappears when doing that. This is the code I used:

public static void setBorderlessFullscreenMode() {
	Gdx.graphics.setUndecorated(true);
	Lwjgl3Graphics.Lwjgl3Monitor monitor = (Lwjgl3Graphics.Lwjgl3Monitor) Gdx.graphics.getMonitor();
	Lwjgl3Graphics.Lwjgl3DisplayMode mode = (Lwjgl3Graphics.Lwjgl3DisplayMode) Gdx.graphics.getDisplayMode(monitor);
	Lwjgl3Window window = ((Lwjgl3Graphics) Gdx.graphics).getWindow();
	GLFW.glfwSetWindowPos(window.getWindowHandle(), monitor.virtualX, monitor.virtualY);
	GLFW.glfwSetWindowSize(window.getWindowHandle(), mode.width, mode.height + 1);
}

This works on both the primary and other monitors. The only downside that I can see is that, well, the window is now one pixel larger than necessary. You would have to account for that in your game. Also, when making a screenshot or recording, the resolution of that would be one pixel larger as well.

(I also noticed that the flickering comes back when the window is already opened and I plug in a second monitor, but I guess monitor plug and play can always lead to strange issues.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Glossary:Windowed - PCGamingWiki PCGW
From PCGamingWiki, the wiki about fixing PC games ... Borderless fullscreen windowed refers to a mode where the game presents the rendered ...
Read more >
Borderless Windowed Mode - Minecraft Feedback
I like fullscreen, but it's annoying when I need to tab out to another window or just interact with another window at all....
Read more >
Demystifying Fullscreen Optimizations - DirectX Developer Blog
Fullscreen Optimizations was designed for gamers to experience the best aspects of both FSE and borderless windowed mode, allowing games to take ...
Read more >
No more "Fullscreen" option only? : r/wow - Reddit
ALT+TAB and click the bottom right of the windows taskbar (bar on bottom of screen, to the right of the clock). You will...
Read more >
Running the game in Borderless Window Mode
If you wish for the game to display at native (desktop) resolution but not in Fullscreen mode, you can do so by applying...
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