Problem with depth buffer in DirectX10

Started by
3 comments, last by Aqua Costa 13 years, 3 months ago
Hello to all,
I'm writing a DirectX10 application and i don't have depth buffering. This is my code:




void Game::InitSwapChain()
{
DXGI_SWAP_CHAIN_DESC sd;
sd.BufferCount = 1;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.Height = mHeight;
sd.BufferDesc.Width = mWidth;
sd.BufferDesc.RefreshRate.Numerator = mRefreshRate;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.Flags = 0;
sd.OutputWindow = mhWnd;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
sd.Windowed = !mFullScreen;
UINT createDeviceFlags = 0;
#if defined(DEBUG)||defined(_DEBUG)
createDeviceFlags |=D3D10_CREATE_DEVICE_DEBUG;
#endif
HR(D3D10CreateDeviceAndSwapChain(NULL,D3D10_DRIVER_TYPE_HARDWARE,0,
createDeviceFlags,D3D10_SDK_VERSION,&sd,
&mSwapChain,&mDevice));
}
void Game::InitRenderTargetView()
{
ID3D10Texture2D* backBuffer;
HR(mSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), reinterpret_cast<void**>(&backBuffer)));
HR(mDevice->CreateRenderTargetView(backBuffer, 0, &mRenderTargetView));
ReleaseCom(backBuffer);
}
void Game::InitDepthStencilView()
{
D3D10_TEXTURE2D_DESC dsdesc;
dsdesc.ArraySize = 1;
dsdesc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
dsdesc.CPUAccessFlags = 0;
dsdesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
dsdesc.Height = mHeight;
dsdesc.Width = mWidth;
dsdesc.MipLevels = 1;
dsdesc.MiscFlags = 0;
dsdesc.SampleDesc.Count = 1;
dsdesc.SampleDesc.Quality = 0;
dsdesc.Usage = D3D10_USAGE_DEFAULT;
mDevice->CreateTexture2D(&dsdesc,NULL,&mDepthStencilBuffer);
mDevice->CreateDepthStencilView(mDepthStencilBuffer,NULL,&mDepthStencilView);
}

void Game::ClearColorDephtStencil(D3DXCOLOR color,
FLOAT depth,UINT8 stencil)const
{
mDevice->ClearRenderTargetView(mRenderTargetView,(FLOAT*)color);
mDevice->ClearDepthStencilView(mDepthStencilView,
D3D10_CLEAR_DEPTH|D3D10_CLEAR_STENCIL,depth,stencil);
}

void Game::OnResize(WPARAM wParam,LPARAM lParam)
{
mWidth = max(LOWORD(lParam),1);
mHeight = max(HIWORD(lParam),1);
ReleaseCom(mRenderTargetView);
ReleaseCom(mDepthStencilView);
ReleaseCom(mDepthStencilBuffer);
mStateMachine->OnScreenResize(lParam,lParam);
HR(mSwapChain->ResizeBuffers(1, mWidth, mHeight, DXGI_FORMAT_R8G8B8A8_UNORM, 0));
InitRenderTargetView();
InitDepthStencilView();
mDevice->OMSetRenderTargets(1, &mRenderTargetView, mDepthStencilView);
SetViewPort();
}
Advertisement
Well it looks correct to me...
What you mean when you say it doesnt work?

Well it looks correct to me...
What you mean when you say it doesnt work?


When i draw two objects the first object is aways drawn behind the second regardless of their position .
Ohhh, the problem wasn't in the initialization. I use ID3DX10Font::DrawText witch changes the default states.

Ohhh, the problem wasn't in the initialization. I use ID3DX10Font::DrawText witch changes the default states.


Thats right, I had the same problem too some time ago...

This topic is closed to new replies.

Advertisement