Why does my opengl scene have problems with the depth buffer?

I read a height map from a file and draw it using triangular stripes.

Height map:

enter image description here

This works well, here's what it looks like:

enter image description here

It looks good, but only from this direction. If you slightly rotate the camera, this will happen:

enter image description here

It seems that my depth buffer is damaged. I turned it on and it works well with a different geometry.

Has anyone had such a problem? I don’t even know what to look for. Thanks!

Edit:

My projection matrix:

1.2062851 0.0 0.0 0.0

0.0 2.1445069 0.0 0.0

0.0 0.0 -1.0 -1.0

0.0 0.0 -0.2 0.0

_fieldOfView(50.0f), _nearPlane(0.1f), _farPlane(10000.0f), _viewportAspectRatio(16.0f/9.0f) 
+5
source share
1 answer

Thanks to everyone for your helpful comments. I have found a problem and hope that others who have this problem will find the solution useful. I had to re-enable depth buffering before each frame (glEnable (GL_DEPTH_TEST)), and not once when creating the renderer. I got the impression that this is a global state, and therefore I do not need to be reset every time I do the rendering.

The final product looks like this: no problem with depth buffer:

enter image description here

Anyway, hope this helps someone.

0
source

Source: https://habr.com/ru/post/1205036/


All Articles