Why does PresentParameters.EnableAutoDepthStencil = true break my scene

Started by
6 comments, last by Madhed 15 years, 7 months ago
I've been having this problem for 2 days now and I can't figure out why enabling the AutoDepthStencil it breaks the scene. The second I enable m_PresentParameters.EnableAutoDepthStencil = true; in the code before my Draw method my scene's triangle cannot be seen, but the grey background can. If I comment out the line I can see the background/triangle fine. Now I've seen in many other example programs people enabling the depth buffer this way and their scene works fine, there's just something funky going on I can't catch. If anybody could provide an explanation as to why I would be very grateful. I could just keep that commented but it wouldn't help much when I needed to use it.

void CD3DObj::Draw(void)
{

	SVertex triangle[] = 
	{ 
		// x, y, z, w, color  coordinates expand from upper left to lower right on screen
		{ GetWidth() / 2.0f, GetHeight() / 3.0f, 15.0f, 1.0f, D3DCOLOR_ARGB(255, 255, 0, 0), }, 
		{ GetWidth() / 1.33f, GetHeight() / 1.2f, 15.0f, 1.0f, D3DCOLOR_ARGB(255, 0, 255, 0), },
		{ GetWidth() / 4.0f, GetHeight() / 1.2f, 15.0f, 1.0f, D3DCOLOR_ARGB(255, 0, 0, 255), },
	};	

	m_pDirect3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 100, 100, 100), 1.0f, 0);

	m_pDirect3DDevice->BeginScene();	

	m_pDirect3DDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);

	m_pDirect3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 1, triangle, sizeof(SVertex));

	m_pDirect3DDevice->EndScene();

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

	Sleep(1); // Give the OS a bit of time to process other things

}

Advertisement
Are you setting the AutoDepthStencilFormat correctly? Does the DX debug output tell you anything useful?
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Random guesses:
1. Your projection matrix has bad clip planes (Near clip is too near, or far clip is too far - try 1.0f and 100.0f respectively)
2. You didn't select an appropriate depth buffer format

Anything from the Debug Runtimes?
I actually didn't set anything with matrices yet. I was building up to eventually using them but I was going for a barebones example in the interim. The tutorial I was using didn't have anything with matrices set.

I'm pretty sure I selected a valid format, I was using a combination of GameTutorials.com intros and two-kings.de/tutorials/dxgraphics/ and both of those work fine on my system.

m_PresentParameters.AutoDepthStencilFormat = D3DFMT_D16;


-> D3DCLEAR_TARGET

gotta be

-> D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL
Quote:Original post by Madhed
-> D3DCLEAR_TARGET

gotta be

-> D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL
Ah, well spotted [smile]

Actually, you'll need to remove the D3DCLEAR_STENCIL flag, since there's no stencil buffer attached.
Huh, good call.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Quote:Original post by Evil Steve
Quote:Original post by Madhed
-> D3DCLEAR_TARGET

gotta be

-> D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL
Ah, well spotted [smile]

Actually, you'll need to remove the D3DCLEAR_STENCIL flag, since there's no stencil buffer attached.


Ah you got me there ;)

This topic is closed to new replies.

Advertisement