Skip to main content
gamedev.net
🔒 Locked

problem with depth buffering

Started by EvilCrap May 4, 2004 at 12:11 AM 3 replies 950+ views
Original Post
EvilCrap
EvilCrap
ive set up my app to do depth buffering from what ive figured from tutorials and things, however, it clearly doesnt work. heres a screen shot of it in its glory, rendering a wavy plane. link from what i figure, depth buffering will use a buffer containing depth values, and if a triangle's pixel value is lower, or closer to the screen, it will overwrite the existing value in the buffer. If this is the case, it wouldnt be necessary to sort and render triangles from back to front, right? this is the code i use to set up the device:
D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof(d3dpp) );
		d3dpp.Windowed = !fullscreen;
		d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;

		d3dpp.BackBufferCount = 1;   
		d3dpp.BackBufferFormat = (fullscreen)? D3DFMT_R5G6B5: D3DFMT_UNKNOWN;
		if( fullscreen){
			d3dpp.BackBufferWidth = width;
			d3dpp.BackBufferHeight = height;
		}
		d3dpp.EnableAutoDepthStencil = TRUE;
		d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

		// Create the D3DDevice

		if( FAILED( m_pDX->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
										D3DCREATE_SOFTWARE_VERTEXPROCESSING,
										&d3dpp, &m_pD3DDevice ) ) )
		{
			return E_FAIL;
		}
		m_pD3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCL);
		// Turn on the zbuffer

		m_pD3DDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
		m_pD3DDevice->SetRenderState( D3DRS_ZWRITEENABLE,  TRUE );
Am i doing anything wrong or missing something? [edited by - evilcrap on May 4, 2004 1:13:03 AM] [edited by - evilcrap on May 4, 2004 1:13:52 AM]
circlesoft
circlesoft
Could you post the code that creates your projection matrix? Using very large values for the far plane can mess up z-buffering. Also, what cull mode are you setting there (I don''t recognize it from the docs - it must have been eliminated in DX9). By default, D3DRS_CULLMODE is set to D3DCULL_CCW, so in most cases, you should use that.


Dustin Franklin
Mircrosoft DirectX MVP
Supernat02
Supernat02
You''re correct about depth buffering.

What is your unit reference? What are the z coordinates of one corner of the flag closest to the screen and one corner farthest into the screen? (the same issue of far plane Dustin mentioned)

You would see a different thing if this was the problem probably, but are you clearing your Z buffer to 1.0 and setting the D3DCLEAR_ZBUFFER bit?

Chris
Chris ByersMicrosoft DirectX MVP - 2005
EvilCrap
EvilCrap
The cull value i use is D3DCULL_CCW, not D3DCULL_CCL.
The vertices are stored in a VB and drawn using DrawPrimitive, their values are 0 to 50 on x and y and sin(y) for z.
Heres my perspective set up:

D3DXMATRIXA16 matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 0.0f, 100.0f );
m_pD3DDevice->SetTransform( D3DTS_PROJECTION, &matProj );


This is my clear/render setup:

m_pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
D3DCOLOR_XRGB(0,0,255), 1, 0 );
if( SUCCEEDED( m_pD3DDevice->BeginScene() ) )
{
m_mesh.render();

m_pD3DDevice->EndScene();
}

m_pD3DDevice->Present( NULL, NULL, NULL, NULL );


EvilCrap
EvilCrap
Ok my problem was that i was setting the MinZ to zero, i set it to 0.009, and it works.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.