It seems DirectX 11 handles Alt+Enter automatically and makes application fullscreen, however without proper parameters it throws warning, therefore I have to fix that. I've done few edits to the code I had and it seems to work correctly (most of the time); in rare cases, when I go from fullscreen to window mode my application's and even other application windows seem to be resized, I've never seen this happen with other games I play, that's why I think I've done something incorrectly. Hopefully you can help me out. Here's the code I have:
Swap Chain initialization:
DXGI_SWAP_CHAIN_DESC SwapChainDesc;
SwapChainDesc.BufferCount = 1;
SwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
SwapChainDesc.BufferDesc.Width = 0;
SwapChainDesc.BufferDesc.Height = 0;
SwapChainDesc.BufferDesc.RefreshRate.Numerator = 0; // application is created in window mode, so I do not set it now
SwapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
SwapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
SwapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
SwapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
SwapChainDesc.OutputWindow = mWindow;
SwapChainDesc.SampleDesc.Count = 1;
SwapChainDesc.SampleDesc.Quality = 0;
SwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
SwapChainDesc.Windowed = 1;
DXGIFactory->CreateSwapChain(mD3D11Device, &SwapChainDesc, &mDXGISwapChain);
Window Procedure (part):
case WM_SYSKEYDOWN:
if(wParam == VK_RETURN && GetAsyncKeyState(VK_MENU)) {
mFullscreen = !mFullscreen;
mSwapChainResized = true;
return 0;
}
break;
Swap Chain resizing (this part is between FrameMove() and FrameRender()):
if(mSwapChainResized) {
mSwapChainResized = false;
SwapChainReleased();
if(mFullscreen) {
DXGI_MODE_DESC SwapChainDesc;
SwapChainDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
SwapChainDesc.Width = mFullscreenWidth;
SwapChainDesc.Height = mFullscreenHeight;
SwapChainDesc.RefreshRate.Numerator = mFullscreenRefreshRate;
SwapChainDesc.RefreshRate.Denominator = 1;
SwapChainDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
SwapChainDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
mDXGISwapChain->ResizeTarget(&SwapChainDesc);
mDXGISwapChain->ResizeBuffers(1, mFullscreenWidth, mFullscreenHeight, DXGI_FORMAT_UNKNOWN, DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH);
mDXGISwapChain->SetFullscreenState(true, 0);
}
else {
mDXGISwapChain->SetFullscreenState(false, 0);
mDXGISwapChain->ResizeBuffers(1, 0, 0, DXGI_FORMAT_UNKNOWN, DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH);
}
SwapChainResized();
}
Thank you in advance.