Sign in to follow this  

Depth Buffer Issue

This topic is 2065 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

Been following a tutorial to try and learn C++ DirectX. So far so good, but depth buffer is giving me problems.

I'll work this into classes after I have a better idea of how it all fits together but here's the code I have so far. The scene renders fine (well except depth buffer not clipping stuff) if I don't put my depth buffer pointer into OMSetRenderTargets() and comment out ClearDepthBuffer();

This makes it pretty obvious to me that it has to do something with how I'm creating the buffer. I've looked up at least 3 different tutorials and tried to adapt their code but none of it seems to work.

I've tried everything I can think of and have been trolling forums for about an hour and nothing suggested seems to work.

I know it's pretty bleh at the second. Just want to get a better idea of how everything works so I don't have to do to rebuild wrapper classes.

//How I Initialize Stuff
[CODE]
void InitRenderTarget()
{ HRESULT hr;
ID3D11Texture2D* pBackBuffer;
pSwapChain->GetBuffer(0,__uuidof(ID3D11Texture2D),(LPVOID*)&pBackBuffer);
hr = pDev->CreateRenderTargetView(pBackBuffer,NULL,&pRenderTargetView);
pBackBuffer->Release();
pBackBuffer = nullptr;
if(hr != S_OK)
{
isPlaying = false;
return;
}
D3D11_TEXTURE2D_DESC texd;
ZeroMemory(&texd,sizeof(texd));
texd.Width = 800.0f;
texd.Height = 600.0f;
texd.ArraySize = 1;
texd.MipLevels = 1;
texd.SampleDesc.Count = 1;
texd.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
texd.BindFlags = D3D11_BIND_DEPTH_STENCIL;
texd.Usage = D3D11_USAGE_DEFAULT;
hr = pDev->CreateTexture2D(&texd,NULL,&pDepthBuff);
if(hr != S_OK)
{
isPlaying = false;
return;
}
D3D11_DEPTH_STENCIL_VIEW_DESC ddesc;
ZeroMemory(&ddesc,sizeof(ddesc));
ddesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
ddesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
pDev->CreateDepthStencilView(pDepthBuff,&ddesc,&pDepth);
pDC->OMSetRenderTargets(1,&pRenderTargetView,pDepth);

pDepthBuff->Release();
pDepthBuff = nullptr;

D3D11_RASTERIZER_DESC rDesc;
rDesc.FillMode = D3D11_FILL_SOLID;
rDesc.CullMode = D3D11_CULL_NONE;
rDesc.DepthClipEnable = true;
rDesc.FrontCounterClockwise = false;
rDesc.MultisampleEnable = false;
rDesc.SlopeScaledDepthBias = false;
rDesc.DepthBias = false;
rDesc.DepthBiasClamp = false;
rDesc.AntialiasedLineEnable = false;
rDesc.ScissorEnable = false;

pDev->CreateRasterizerState(&rDesc,&pRastState);
pDC->RSSetState(pRastState);

//SetupViewPort
D3D11_VIEWPORT viewport;
ZeroMemory(&viewport,sizeof(D3D11_VIEWPORT));
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = 800;
viewport.Height = 600;
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f;
pDC->RSSetViewports(1,&viewport);
}
[/CODE]

//How I do some basic drawing
[CODE]
void RenderFrame()
{
pDC->ClearRenderTargetView(pRenderTargetView,ClearColor);
pDC->ClearDepthStencilView(pDepth,D3D11_CLEAR_DEPTH,1.0f,0.0f);
pDC->Draw(3,0);
World2.MakeRotateY(VM_PI*gTimer.TotalTime());
World2.Translate(1.0f,0.0f,0.0f);
World2.RotateY(VM_PI_4*gTimer.TotalTime());
Matrix4x4::MatrixMultiply(World2,View,World2);
pDC->UpdateSubresource(pCBuffer,0,0,&World2,0,0);
pDC->Draw(3,0);
pSwapChain->Present(0,0);
}
[/CODE]

Share this post


Link to post
Share on other sites

This topic is 2065 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this