Fullscreen bug with low resolutions

The resolutions are taken from GraphicsAdapter.DefaultAdapter.SupportedDisplayModes
My screen is 1920x1080
Any resolution above 1280x960 works fine in fullscreen. However 1280x960 and below becomes borderless without filling the screen when fullscreen is enabled. If the resolution changes when the it’s already fullscreen with a resolution above 1280x960 for example 1920x1080 to 1280x960 or below it works as intended. Also generally low resolutions becomes stretched and blurry. A game like Rogue Legacy that was made with XNA always looks good no matter the resolution, it has the same selection of resolutions.

Is this a directx project or cross platform desktop?

I’m pretty sure it’s cross platform.

What version of MonoGame are you using? If it’s a recent version (3.6+) could you open an issue on the GitHub page, please ( https://github.com/MonoGame/MonoGame/issues
)? If not can you upgrade and see if that helps?

How do I upgrade my pre-existing project on Visual Studio 2015? Do I have to make a new project and copy all the files to it?

If you started from a template, yes. I’d say that’s easiest.

Okay, updated. Now if the resolution is changed it will be borderless regardless of fullscreen or windowed.

Can you share the code that triggers the borderlesness when windowed? And can you confirm that this is a DesktopGL project (it will have x86 and x64 folders with dependencies).

I was setting Game.Window.Position to Point.Zero. So it wasn’t borderless, the border was just offscreen, didn’t think the border didn’t count. Now I feel like an idiot.

I still have some problems though. If I change the resolution while fullscreen, the screen just goes black. If I set the resolution to my screen size while windowed, it fills the whole screen instead of leaving some room for the border and if I try to then turn on fullscreen it goes black. If I alt-tab out and in again it’s no longer black. I’m changing resolution with PreferredBackBufferWidth and Height and changing fullscreen with IsFullScreen.

Yes, it’s the client window position you’re setting. No problem :slight_smile:

Not sure what you’re expecting… That’s how it should be, right?

I have a PR up that fixes some issues with windowing in dx projects. I haven’t had a chance to finish it yet, but hopefully will soon. You can try to work around the other issues (maybe calling GraphicsDevice.Reset again when you get a black screen works for a simple fix) or use a modified version of MG with fixes from my PR: https://github.com/MonoGame/MonoGame/pull/5585

Good, that’s how you should use the API. People sometimes think they can directly modify GraphicsDevice.PresentationParameters, but getting that makes a copy of the parameters so that won’t work. For reference, the 3 ways to change PresentationParameters are:

  1. Use GraphicsDeviceManager.[property] to set preferred values, then call GraphicsDeviceManager.ApplyChanges (only when settings are applied outside your Game constructor).
  2. Modify PresentationParameters in the GraphicsDeviceManager.PreparingDeviceSettings event (this overrides preferred settings in GraphicsDeviceManager.
  3. Call GraphicsDevice.Reset(PresentationParameters) with the desired PresentationParameters..

Hmm, calling GraphicsDevice.Reset doesn’t seem to fix the problem.

Damn, thought that would work…

So… do you have any other ideas?

I’d have to look into it, don’t have time for that atm :confused: Try building my branch if you really want this fixed. Things should be better (but not 100% right).

I don’t really know what you mean by “building” your branch. I’m supposed to replace my version of MonoGame with it, right? I installed the templates for visual studio 2015 via an installer. What version was it built upon and what happens when a new version of the official MonoGame comes out?

It just bugs me that this bug is so easy to trigger. Just change resolution when fullscreen. How could they miss that one? I’m going to try to start a new project and go fullscreen and change resolution to rule out the possibility of something other in my code triggering it.

I created a new cross-platform desktop GL project and enabled fullscreen in Game.Initialize or by button press with this code:
graphics.IsFullScreen = true; graphics.ApplyChanges();
Then I inserted this into the Update method and if I press “R” I get the black screen
if (Keyboard.GetState().IsKeyDown(Keys.R)) { graphics.PreferredBackBufferWidth = 1920; graphics.PreferredBackBufferHeight = 1080; graphics.ApplyChanges(); }
Next I’m going to try another PC with this project to rule out the possibility of something being wrong with my PC, feel free to also try out this code. BTW Preferred width and height can be anything and it will still trigger the bug.

Edit: I tried it on another laptop (Windows 8.1) and it works fine, but not on my main laptop (Windows 10).

Hello,

I had the same problem. I could circumvent it by temporarly switching to windowed mode, changing the resolution, and then switching back to fullscreen. Here’s my working code:

public void SetResolution( int width, int height )
{
    bool changed = this.GraphicsDeviceManager.PreferredBackBufferWidth != width || this.GraphicsDeviceManager.PreferredBackBufferHeight != height;
    bool fullscreen = this.GraphicsDeviceManager.IsFullScreen;

    if (changed)
    {
        // Fix for game window not switching correctly in fullscreen mode.
        // See http://community.monogame.net/t/fullscreen-bug-with-low-resolutions/9341
        if (fullscreen)
        {
            this.GraphicsDeviceManager.IsFullScreen = false;
            this.GraphicsDeviceManager.ApplyChanges();
        }
        
        this.GraphicsDeviceManager.PreferredBackBufferWidth = width;
        this.GraphicsDeviceManager.PreferredBackBufferHeight = height;

        if (fullscreen)
        {
            this.GraphicsDeviceManager.IsFullScreen = true;
        }

        this.GraphicsDeviceManager.ApplyChanges();
    }
}

Hope this helps!

1 Like

I tried it and it worked, of course. It doesn’t matter what the cause of the problem is because the solution is so simple: Just go out of fullscreen before changing resolution. I don’t know if it has something to do with Windows 10, or certain PC’s only, but it’s good to implement this anyway if you plan to release your game.

The only downside is that it takes twice as long to change resolution when fullscreen because you first go out of fullscreen and apply changes and then change the resolution and go back to fullscreen and apply changes again, but thanks for sharing.

Basically, I’m just a little disappointed that MonoGame has this pretty fundamental bug.

It’s clearly not related to Windows 10 as I develop with Windows 7 only.