Jump to content
  • Advertisement
Sign in to follow this  
Squidmaster

OpenGL Depth-related problem...

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

Share this post


Link to post
Share on other sites
Advertisement
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...

Share this post


Link to post
Share on other sites
When you switched to GL from D3D, did you change your perspective matrix over from a D3D style one to a GL style one?

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!