Hey there. I am having a severe bug in my game trying to implement a borderless fullscreen feature. The feature works okay, except for the fact that the back buffer does not scale into the window size if the back buffer size does not match the window’s.
Here’s an example of what I mean.
This first screenshot is taken with the game running at 1080p after a fresh start in borderless fullscreen. My laptop’s native resolution is 1080p and so the window’s size is 1080p, matching the back buffer width. Everything renders fine.
The next screenshot is what happens when I change the resolution to 1600x900 without restarting the game. The window’s client size is still 1080p, but the back buffer size no longer matches. The blue rectangle shows the back buffer’s area. It is rendering from the bottom left and there’s a large amount of black where there shouldn’t be.
This next screenshot shows what happens if I keep my settings as is in the previous one, but then restart the game. It’s the same bug, except that the back buffer is rendering from the top left this time.
Changing the game’s resolution back to 1920x1080 fixes the problem. Am I doing anything wrong? Here’s the code for setting my display mode. I’m using .NET Core and DesktopGL.
public void SetDisplayMode(DisplayMode displayMode, FullScreenMode fullscreenMode)
{
// fullscreen mode
switch (fullscreenMode)
{
case FullScreenMode.Borderless:
_graphics.IsFullScreen = true;
_graphics.HardwareModeSwitch = false;
break;
case FullScreenMode.FullScreen:
_graphics.IsFullScreen = true;
_graphics.HardwareModeSwitch = true;
break;
case FullScreenMode.Windowed:
_graphics.IsFullScreen = false;
_graphics.HardwareModeSwitch = true;
break;
}
// resolution
_graphics.PreferredBackBufferWidth = displayMode.Width;
_graphics.PreferredBackBufferHeight = displayMode.Height;
// Force the GUI to update since the resolution has changed.
GuiManager.ForceLayoutUpdate();
// applu changes.
_graphics.ApplyChanges();
}
I have confirmed that both GraphicsDevice.PresentationParameters
and GraphicsDevice.Viewport
are being updated with the correct settings. The game’s display mode IS being properly updated, but it seems there’s a bug with how the back buffer is drawn to the screen. Any help is greatly appreciated!