1

I am working on a low resolution 2D game using the DirectXTK and Spritebatch. Everything works fine in windowed mode, however whenever I start or switch to fullscreen the image is blurred to stretch the backbuffer to fit the screen.

I Initialise the device and swap chain with these settings:

DXGI_SWAP_CHAIN_DESC scd = { 0 };
scd.BufferCount = 1;
scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
scd.BufferDesc.Width = width;
scd.BufferDesc.Height = height;
scd.BufferDesc.RefreshRate.Numerator = 0;
scd.BufferDesc.RefreshRate.Denominator = 0;
scd.BufferDesc.Scaling = DXGI_MODE_SCALING_CENTERED;
scd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
scd.OutputWindow = m_hWnd;
scd.SampleDesc.Count = 1;
scd.SampleDesc.Quality = 0;
scd.Windowed = !m_fullscreen;
scd.Flags = 0;
scd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;`

And the sampler state is set up as follows:

D3D11_SAMPLER_DESC sd = {};
sd.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
sd.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
sd.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
sd.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
sd.MaxAnisotropy = (m_D3DDevice->GetFeatureLevel() > D3D_FEATURE_LEVEL_9_1)?D3D11_MAX_MAXANISOTROPY:2;
sd.MaxLOD = D3D11_FLOAT32_MAX;
sd.ComparisonFunc = D3D11_COMPARISON_NEVER;

In the windows message handler I recreate the resources when the window size changes, if I use the new window size as the backbuffer dimensions or original game dimensions the game is blurred either way.

Does anyone know how to resolve this issue? Can Chuck Walbourn user:3780494 shed some light on the situation?

Thank you so much.

ball
  • 39
  • 7
  • The key part is the call to ``SetViewport``. DirectX Tool Kit's SpriteBatch is primarily driven by that. You are probably forgetting to reset the viewport when you change render target size. – Chuck Walbourn Mar 07 '21 at 21:44
  • I'm setting the viewport after creating the render target view like this: `m_viewport.Width = (float) GameWidth; m_viewport.Height = (float) GameHeight; m_viewport.MinDepth = 0.0f; m_viewport.MaxDepth = 1.0f; m_viewport.TopLeftX = 0; m_viewport.TopLeftY = 0; m_D3DDeviceContext->RSSetViewports(1, &m_viewport);` And this is run everytime the window size changes. Am I doing it right? – ball Mar 09 '21 at 20:28
  • Hmm.. I'd suggest looking at your backbuffer resizing then. You may want to look at the templates in [directx-vs-templates](https://github.com/walbourn/directx-vs-templates). – Chuck Walbourn Mar 13 '21 at 19:16
  • Thank you. I'll look through the template and see what I'm doing wrong. I have realised that when I go fullscreen, the width and height parameters in the WM_SIZE message are not the full 1920 x 1080 native screen resolution but a lower value, maybe this is what is causing it? – ball Mar 24 '21 at 22:02
  • Remember that you have to manipulate the Windows styles to get 'native' size. See my templates for how I handle it. – Chuck Walbourn Mar 24 '21 at 22:31
  • I've been looking through the template and trying to match the implementation and not having much luck. https://bitbucket.org/balldrix/hive-project/src/master/ Here is the repo if you get time to have a look. The branch I'm working on is the feature/fullscreen-fix branch. – ball Mar 25 '21 at 22:15

1 Answers1

1

Thank you to Chuck Walbourn for pointing me to the DirectXTK templates.

After changing my Graphics class to match the template, the full screen on longer blurs.

Although I am not changing the backbuffer screen resolution It needs to be unchanged so that the low resolution is stretched to fit the window. If I change the backbuffer it is difficult to see the game because it is then rendered so small.

It appears the reason the fullscreen mode is not blurred when using the template is because it is actually borderless windowed mode and not exclusive fullscreen.

ball
  • 39
  • 7