Jump to content
  • Advertisement
Sign in to follow this  
ChaseRLewis

Depth Buffer Issue

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

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);
}


//How I do some basic drawing

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);
}

Share this post


Link to post
Share on other sites
Advertisement
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!