Depth Buffer

Started by
3 comments, last by Cleese852 14 years, 11 months ago
Hi, I'm have trouble getting my depth buffer enabled, even though I did it before and succeeded.. These are my present parameters: m_presentParameters.BackBufferWidth = DEFAULT_BACKBUFFER_WIDTH; m_presentParameters.BackBufferHeight = DEFAULT_BACKBUFFER_HEIGHT; m_presentParameters.BackBufferFormat = D3DFMT_X8R8G8B8; m_presentParameters.BackBufferCount = 1; m_presentParameters.MultiSampleType = D3DMULTISAMPLE_NONE; m_presentParameters.MultiSampleQuality = 0; m_presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; m_presentParameters.hDeviceWindow = ENGINE->getWindow(); m_presentParameters.Windowed = TRUE; m_presentParameters.EnableAutoDepthStencil = TRUE; m_presentParameters.AutoDepthStencilFormat = D3DFMT_D16; m_presentParameters.Flags = 0; m_presentParameters.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; m_presentParameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; And I also have the renderstates: HR(m_devicePtr->SetRenderState(D3DRS_ZWRITEENABLE, TRUE)); HR(m_devicePtr->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE)); HR(m_devicePtr->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL)); And before I draw I clean my screen with this: HR(m_devicePtr->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, m_backgroundColor, 1.0f, 0 )); Am I forgetting something, because I can't seem to find out why it won't work, I googled for hours, even my teacher at school hasn't found the problem yet :-/ Thanks in advance
Advertisement
What you've posted there looks okay. Exactly what sort of behavior are you getting?

Also, make sure you're not doing anything that will set render states. For instance ID3DXSprite will set render states, and an ID3DXEffect can set render states as well.
Here's a screenshot: http://img16.imageshack.us/img16/3871/zbufferproblem.jpg
I disabled my ID3DXSprite and I'm not setting any renderstates through an ID3DXEffect or my shader. I analyzed my application with PIX (from directX SDK) and it appears my depth buffer is black, except for the text I draw, which is white.
You only have a 16-bit Z-buffer, which means you have very limited precision. What are your near and far clip planes set to in your projection matrix? You want your near clip as far as possible (And with a 16-bit Z-buffer you want it >= 1.0f) and your far clip as near as possible (With a 16-bit Z-buffer I wouldn't put it at anything past 1000.0f, and even that is a pretty poor resolution).
Ah goddamnit, I found it. Although I was setting my near to 30 and far to 500 for testing, It appeared that I was giving the wrong variables to my createProjection function. So I was using 0-3000 instead for my clip planes -.-
Now it's solved, thanks!

This topic is closed to new replies.

Advertisement