Jump to content
  • Advertisement
Sign in to follow this  
Prince of Cats

[solved] z-buffer won't switch on

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

I am probably being stupid here but I broke my Z-buffer and cannot understand what I did or how. edit: Near draw was set to zero... My initialise sub
Quote:
bool InitialiseDirect3D()
{

	gpdx = Direct3DCreate9(D3D_SDK_VERSION);	//	Create a D3D9 interface

	if(!gpdx)			//	If it failed
		return FALSE;	//	might as well give up now

	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory( &d3dpp, sizeof(d3dpp) );	//	Just in case the memory was used before and left with data

	D3DDISPLAYMODE mode;
	gpdx->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &mode);	

	d3dpp.Windowed   = WINDOWED;			//	Run in a window, TRUE or FALSE - currently set by a #define
	
	d3dpp.BackBufferCount = 2;				//	2 Backbuffers - smooth but good response
	d3dpp.BackBufferWidth = 1024;			//	Width of the screen (for the purposes of drawing boxes)
	d3dpp.BackBufferHeight = 768;			//	Height of the screen (for the purposes of drawing boxes)
	d3dpp.BackBufferFormat = mode.Format;	//	Use current value
	
	d3dpp.PresentationInterval = D3DPRESENT_DONOTWAIT;			//	Draw when ready
	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;	//	Use default refresh rate
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;					//	Use most efficient
	d3dpp.hDeviceWindow = hWnd;									//	Use this window

	d3dpp.EnableAutoDepthStencil = TRUE;						//	Enable AutoDepthStencil
	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;					//	16-bit

	if(FAILED(gpdx->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &gddevice)))
		return FALSE;	//	Create or exit, you know the drill...

	return TRUE;	
}
My main loop (trimmed back to just the relevant parts)
Quote:
while(KeepRunningMyGame)
{	// Gaming loop
	{
		//	Clear everything
		gddevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(192, 0, 0), 1.0f, 0);
		gddevice->BeginScene();	//	Begin

		// Setup our projection and view transformations.
		SetupWorld();

		// Render Output
		RenderAll();

		gddevice->EndScene();	//	Scene ends
		gddevice->Present(NULL, NULL, NULL, NULL);	//	Draw it
		}
	}	//	Loops until (!KeepRunningMyGame)
My render sub
Quote:
void RenderAll()
{	//	Render the scene

	// kill Z-Buffer and Lighting
	gddevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);	//	Disable Z-Buffer
	gddevice->SetRenderState(D3DRS_LIGHTING, FALSE);		//	Disable Lighting

	// Draw Sky without lighting or Z-buffer, so that the scene is drawn over the sky
	gpmSky->Render_Relative(D3DXVECTOR3(0.0f,0.0f,0.0f));

	gddevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);	// Restart Z-Buffer

	//	All graphics from this point on are drawn over the skybox.

	gpmSol->Render(camPos);		//	Render Sol with full lighting to mimic emissive

	gddevice->SetRenderState(D3DRS_LIGHTING, LIGHTS_ON);	//	Restart lighting
				
	//	Render dummy ships
	gpmDummy[0]->Render(camPos);
	gpmDummy[1]->Render(camPos);
	gpmDummy[2]->Render(camPos);
	gpmDummy[3]->Render(camPos);

	//	Render the planets
	gpmVenus->Render(camPos);
	gpmTerra->Render(camPos);
	gpmLuna->Render(camPos);
	gpmMars->Render(camPos);

	RenderText();	//	Render any text output over the top
}
[Edited by - Prince of Cats on April 24, 2007 11:33:42 AM]

Share this post


Link to post
Share on other sites
Advertisement
What does "broke my Z-buffer" actually mean? Is it not working at all? are you getting artifacts? Is the debug output saying it's broken?

Share this post


Link to post
Share on other sites
Sorry, I should clarify.

The code compiles fine, but objects are being drawn over the earlier objects as though I was not switching the z-buffer back on. I am a little concerned by this, since it used to work and now it doesn't, but I didn't notice when it stopped working...

Share this post


Link to post
Share on other sites
Quote:
Original post by Prince of Cats
void RenderAll()
{ // Render the scene

// kill Z-Buffer and Lighting
gddevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); // Disable Z-Buffer
gddevice->SetRenderState(D3DRS_LIGHTING, FALSE); // Disable Lighting

// Draw Sky without lighting or Z-buffer, so that the scene is drawn over the sky
gpmSky->Render_Relative(D3DXVECTOR3(0.0f,0.0f,0.0f));

gddevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); // Restart Z-Buffer

// All graphics from this point on are drawn over the skybox.

gpmSol->Render(camPos); // Render Sol with full lighting to mimic emissive

gddevice->SetRenderState(D3DRS_LIGHTING, LIGHTS_ON); // Restart
}


1) You're rendering the Sky without Z-buffer. If the sky is a bit complex, that may be the source of your problem.

2) May be your problem looks like a Z-buffer problem but it isn't. Try disabling it & see if any difference

3) 16-bit stencil.... mmm... I don't see in your init stuff that you're requesting Z-buffer to be attached to the backbuffer (sorry if I don't use D3DX, may be it's enabled by default). A 16-bit stencil may not be supported by your card, furthermore you may need 32-bit colour mode to work (may be windowed mode is also not suported)

4) use SVN or alike tools in the future to track "previously working" issues

Share this post


Link to post
Share on other sites
Quote:
1) You're rendering the Sky without Z-buffer. If the sky is a bit complex, that may be the source of your problem.

The sky is a basic cube with all the normals flipped to point inward. 12 tris, one texture.

Quote:
2) May be your problem looks like a Z-buffer problem but it isn't. Try disabling it & see if any difference

No change. The Z-buffer is just not switching back on after I render the skybox.

Quote:
3) 16-bit stencil.... mmm... I don't see in your init stuff that you're requesting Z-buffer to be attached to the backbuffer (sorry if I don't use D3DX, may be it's enabled by default).

That might be it, I may have broken it when I fiddled with the back-buffer...

Quote:
A 16-bit stencil may not be supported by your card, furthermore you may need 32-bit colour mode to work

16-bit worked before...

Quote:
(may be windowed mode is also not suported)

No, tried this too.

Quote:
4) use SVN or alike tools in the future to track "previously working" issues

That is actually a great idea.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!