I'm trying to learn DX11 using this tutorial http://www.directxtutorial.com/Lesson.aspx?lessonid=11-4-4 but I'm having a few issues.
Up to this tutorial (Going fullscreen) everything works (I get a nice red window as expected), but after implementing this tutorial switching to full screen doesn't appear to be working. When I hit alt+enter I can see the visual change (back screen with just a cursor for about 1-2 seconds) before it switches back to the normal windowed mode. I'm not sure why the full screen doesn't appear to be sticking.
Another issue is that the tutorial mentions removing hbrBackground from the windowclass, but this will cause my D3D11CreateDeviceAndSwapChain to fail with a DXGI_ERROR_INVALID_CALL.
I'm using the following code to create my window
void CWindow::create(HINSTANCE hInstance, int width, int height) {
WNDCLASSEX windowClass;
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style = CS_CLASSDC | CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = WndProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = hInstance;
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1);
windowClass.lpszMenuName = NULL;
windowClass.lpszClassName = "EngineWindowClass";
windowClass.hIconSm = NULL;
RegisterClassEx(&windowClass);
m_hWnd = CreateWindowEx(WS_EX_LEFT, "EngineWindowClass", "Test window", WS_OVERLAPPEDWINDOW, 0, 0, width, height, NULL, NULL, hInstance, NULL);
ShowWindow(m_hWnd, SW_NORMAL);
UpdateWindow(m_hWnd);
};
And the following code to initialize D3D (WNDOW_WIDTH and WINDOW_HEIGHT are 2 defines passed to the window create function, values are set to 800 and 600)
void initD3D(HWND hWnd) {
// Create swap chain/device
DXGI_SWAP_CHAIN_DESC scd;
ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));
scd.BufferCount = 1;
scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
scd.BufferDesc.Width = WINDOW_WIDTH;
scd.BufferDesc.Height = WINDOW_HEIGHT;
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
scd.OutputWindow = hWnd;
scd.SampleDesc.Count = 1;
scd.SampleDesc.Quality = 0;
scd.Windowed = TRUE;
scd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
HRESULT result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL, D3D11_SDK_VERSION, &scd, &swapChain, &device, NULL, &deviceContext);
console.printf("result: %x\n", result);
// Create render target
ID3D11Texture2D* pBackBuffer;
swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer);
device->CreateRenderTargetView(pBackBuffer, NULL, &backBuffer);
pBackBuffer->Release();
deviceContext->OMSetRenderTargets(1, &backBuffer, NULL);
// Set view port
D3D11_VIEWPORT viewport;
ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = WINDOW_WIDTH;
viewport.Height = WINDOW_HEIGHT;
deviceContext->RSSetViewports(1, &viewport);
}
Perhaps I'm missing something obvious (first time dealing with DX), but I cant seem to find it.