View Full Version : Weird rendering of a mesh

04-01-2004, 06:31 PM

I create a Mesh from scratch (thanks Clootie for the link), namely a fractal world. It's very basic mesh : a grid (x,y coordinates), with a different height (z) for each point, and then 2 triangles to render each quad. I kept it as simple as possible.

When I render it, some faces that should be hidden by others are still visible. It's as if DirectX did not manage to properly order the faces to render.

Here is an image link as an illustration (B&W stripes to better see the volume):

A few things I noted:

1. It only happens in certains views (see above link: left image is fine, right one is not), probably due to the initial ordering of the vertex.

2. Let's say I have 3 faces: A > B > C, where > means 'in front of'. It seems that in that case, C is always correctly hidden, but B might sometimes be rendered in front of A.

Any idea what happens? Where should I look? Can it be because the mesh is too complex (4225 vertex, 8192 faces)?


04-01-2004, 08:58 PM
What is your projection matrix? I have bad feelings about your Znear and Zfar values. Have you enabled Z buffer at all?

04-01-2004, 10:56 PM

g_pd3dDevice.SetRenderState(D3DRS_ZENABLE, iTrue);

Projection matrix:

D3DXMatrixPerspectiveFovLH(matProj, D3DX_PI/4, 1.0, 1.0, 200.0);
g_pd3dDevice.SetTransform(D3DTS_PROJECTION, matProj);

The map is 64*64. 200 is more than enough.

Any clue? :?

04-01-2004, 11:15 PM
I was not clearing the zbuffer properly... Hence, the scene was rendered using the zbuffer of the first frame over and over, which is why the scene appeared perfect from some angles, and somewhat ok from others, but never completely chaotic as we could have expected if zbuffer was not working at all.

Rookie's mistake. :oops:

Thanks for your time.