#### Archived

This topic is now archived and is closed to further replies.

# Z issue

## Recommended Posts

helix    301
I have a simple demo I''m working on and I''ve been struggling with this bug for a while now. In my main render function call, I call the render function for all my other objects -- my room, a list of sphere objects, my weapon effect, and my UI. I''ve noticed that each render call''s Z ordering is separate from the rest. So for example, my list of sphere''s and the particle system it owns get''s drawn correctly but the next function call for my weapon effect is not properly ordered with the balls Z orders. I do turn off the Z test for my particle system (g_pGame->GetDevice()->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE ) but turn it back on when I''m done. That shouldn''t affect it should it? It''s driving me nucking futs!!

##### Share on other sites
helix    301
How do you clear it? I don''t think I am, the only operation that affects the z buffer is the line I included above:

g_pGame->GetDevice()->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );

##### Share on other sites
Fuzztrek    572
before you begin each scene, you should be clearing the display. This function can also clear the z-buffer (like-so):

  g_pGame->GetDevice()->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_RGBA(0,0,0,255), 1.0f, 0);

This should change _something_!!

Hope it helps.

Fuzztrek

¬_¬

##### Share on other sites
helix    301
oh lol, I do that, but not in between each render function call. Just at the start of each frame.

##### Share on other sites
Fuzztrek    572
you should just have to do it at the start of each frame..

¬_¬

##### Share on other sites
helix    301
Update on this. I was talking to a friend of mine and he said he thought that if you turn off the zbuffer then back on in the middle of a render call, it''ll mess it up. He said that I should save the rendering of the entities that don''t need the zbuffer last. Would that fix it?

##### Share on other sites
No, changing rendering states mid-scene shouldn''t mess anything up. If you hold off rendering non-zbuffered objects until last, than those objects will overwrite everything regardless.

What does your function call to turn the zbuffer back on? What''s the code to create a zbuffer look like? Maybe you should post a screenshot of the effect.

home.att.net/~rpgbook
Author, Programming Role-Playing Games with DirectX
and Focus On: Advanced Animation with DirectX

##### Share on other sites
helix    301
hmm, well now it looks like it is working so I guess you're right. odd...

[edited by - Jim Adams on October 7, 2002 3:46:14 PM]