Sign in to follow this  

Problems with ZBuffer

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

Hello.I have a Vertex Buffer that contains a lot of triangle that form different things.I set up the Z Buffer (like in DirectX SDK) but I wan't to draw: DrawPrimitives(D3DPT_TRIANGLESTRIP,16,10); // Some borders for examples ..... DrawPrimitives(D3DPT_TRIANGLESTRIP,0,16); // Background ..... The problem is that it is not in Z order.Is in the order like the code that I written up.In front is the background and I don't see the borders because the z order is not working....I don't now how to explain any more....sorry for my bad english

Share this post


Link to post
Share on other sites
Hope I'm not wasting your 0 replies :p. If the Z-buffer is working and your not using an alpha-channel for alpha blending then it does not matter what order you render things in. If the Z-buffer is working properly everything should look like it is depth sorted.

Reading through your post, there are two things I can think. One... Are you rendering 2D images at the same depth value? If you are rendering 2D images you need to DISABLE the depth buffer and render them in the correct order so that they just lay on-top of each other.

If those are 3D objects that you are trying to render and they are in the correct world positions, then what kind of debugging have you done? Make sure that DirectX is not failing on the depth buffer creation. Also, make sure to TURN ON depth testing. I'm not sure if it is defaulted on or off. I'd also recommend that you turn backface-culling on if you don't, even though that probably wouldn't help your issue. :p

// Turning on and off the depth buffer
<your_pDevice>->SetRenderState(D3DRS_ZENABLE,true/*false*/);

Share this post


Link to post
Share on other sites
I don't fully understod your problem, but maybe you could render the background first and then disabling depth buffering (pd3dDevice->SetRenderState( D3DRS_ZENABLE, FALSE);) and then render the border.

Share this post


Link to post
Share on other sites
I will try to explain better..
- My aplication has a background, borders, start animation
- All the verteces are in one vertex buffer,in one struct CUSTOMVERTEX (background and borders have their own DWORD COLOR, and the start animation (with texture)
#define CUSTOMFVF (D3DFVF_XYZ | D3DFVF_DIFFUSE |D3DFVF_TEX1)
- Borders are on the Z axes in front of the background (-919.0f Borders and -920.0f Background) - this values are so big because I wanted the X = 1024.0f (+512.0f - -512.0f) and Y = 768....
- The ZBuffer is enabled and cleared when the render begin
- When the application starts I wan't to display 1 - the borders 2 - animation things 3 - background
- Here the background is over the borders.Why?How about the Z order?

Code for Zbuffer:
(in Presentation Parameters)
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
....
(After Vertex Buffer create)
d3ddev->SetRenderState(D3DRS_ZENABLE, TRUE); // turn on the z-buffer
....
(Render)
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);



Share this post


Link to post
Share on other sites
Quote:
Original post by johnny_no1_boy
(Render)
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
That doesn't clear the Z-buffer. You want:
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

Share this post


Link to post
Share on other sites
sorry....i posted the wrong code line...i have this 2 code line....
VideoCard_Device->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0); VideoCard_Device->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

so...still not working

[Edited by - johnny_no1_boy on August 3, 2007 7:31:20 AM]

Share this post


Link to post
Share on other sites

This topic is 3785 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this