Question

I'm a beginner to DirectX, so the solution may seem obvious to you. I'm following this tutorial teaching me how to set up a simple directx project with no starting code, and so far the tutorials are working perfectly. The problem is now that I have it clearing the backbuffer in my Render() function, it will not set the background to any color but black.

Here's my Render() function:

//set render target
devcon->OMSetRenderTargets(1, rendertarget.GetAddressOf(), nullptr);

//clear backbuffer to blue
float color[4] = { 0.0f, 0.2f, 0.4f, 1.0f };
devcon->ClearRenderTargetView(rendertarget.Get(), color);

//TODO: Render code here

//swap buffers
swapchain->Present(1, 0);

and my setup in the initialization:

//get a ptr to the backBuffer
ComPtr<ID3D11Texture2D> backbuffer;
swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), &backbuffer);

//create a render target pointing to the backBuffer
dev->CreateRenderTargetView(backbuffer.Get(), nullptr, &rendertarget);
Was it helpful?

Solution

Your code for clearing the back buffer to blue is correct.

There must be a type or failure somewhere else.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top