Jump to content
  • Advertisement
Sign in to follow this  
gixslayer

DX11 Trouble following tutorial

This topic is 1345 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Edited by gixslayer

Share this post


Link to post
Share on other sites
Advertisement

Did some more debugging, the reason the D3D11CreateDeviceAndSwapChain call fails is because hWnd is null (removing hbrBackground will cause the class to fail to register with an error code 0x57 ERROR_INVALID_PARAMETER, am I right to assume this might just be a mistake in the tutorial?). I'm still not sure why my fullscreen doesn't work however.

Share this post


Link to post
Share on other sites

am I right to assume this might just be a mistake in the tutorial?


I believe it is a mistake.
I tried it on a rastertek tutorial and it crashes immediately.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!