Skip to main content
GameDev.net gamedev.net
🔒 Locked

Depth-related problem...

Started by Squidmaster May 25, 2013 at 9:15 PM 3 replies 1.4k views
Original Post
Squidmaster
Squidmaster
I've recently moved over from Direct3D to OpenGL and have started running into a problem with the display of some of my meshes. While "2D" graphics all display just fine, 3D meshes seem to handle depth-testing very oddly.

3bvbm.jpg

As you can see, when the lighter mesh overlaps the darker mesh it gets drawn "underneath" it, and vice-versa. My first thought was that either depth-testing, depth-writing, or the depth function had something going on with them but even when I explicitly enable everything right before rendering my meshes and play around with the depth function nothing seems to change. Disabling depth-testing and such does what you'd expect (ie, the meshes are drawn in the order specified and one is always overlapping the other).

A render pass from start to finish involves the following: I clear, reset my matrices, enable depth-testing and -writing, enable GL_xyz_ARRAY for the VBOs, bind them, bind their texture and render them, disable GL_xyz_ARRAY, and swap buffers. The mesh itself is just a simple heightmap-based mesh generated at load time.

I'm a little in the dark as to what may be involved and I'd rather not spam-post the entire code but I'll gladly post source for any part of the program if needed.
Squidmaster
Squidmaster
Yup! Once, at the start of every frame.

glClear((p_clearColor ? GL_COLOR_BUFFER_BIT : NULL) | GL_DEPTH_BUFFER_BIT);

(As a test, I tried clearing the depth immediately before rendering my two meshes and nothing changed).

---

Okay, so I found that setting...

glClearDepth(0);
glDepthFunc(GL_GREATER);

...right before I draw fixes the problem. At least I can move ahead some now, but...

1- I still don't know what happened. Or why.
2- This... feels like a hack more than a fix. I feel like this'll eventually break on someone else's computer; this isn't how depth is supposed to go AFAIK...
BornToCode
BornToCode

Enable Depth Testing,

Set your depth func to glDepthFunc(GL_LEQUAL);

and set ClearDepth(1.0f)

Hodgman
Hodgman
When you switched to GL from D3D, did you change your perspective matrix over from a D3D style one to a GL style one?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.