Fullscreen bug with low 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.

I’m pretty sure this issue is fixed in my branch that I linked above. Hopefully it’ll get merged soon, but it helps if you can verify it and post back.
Link to pull request: https://github.com/MonoGame/MonoGame/pull/5585

To try it out follow these steps:

  1. You’ll need to build MG from source. Steps for that are in the docs: http://www.monogame.net/documentation/?page=Setting_Up_MonoGame_Source
  • Then you’ll need to add my fork as a remote so you can check out the changes. In the MonoGame folder that you cloned in the first step, run git remote add jjagg https://github.com/Jjagg/MonoGame.git.
  • Fetch my windx branch from my fork: git fetch jjagg windx
  • Check out the branch: git checkout jjagg/windx
  • Then build MG like you normally would (make sure to run Protobuild again first) and add a reference to the local MG projects in your game project as mentioned in the docs under ‘Referencing the projects’