Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my opengl scene have depth buffer problems?

Tags:

c++

opengl

I am reading a heightmap from a file, and rendering it using triangle strips.

The heightmap:

enter image description here

It works well, this is how it looks :

enter image description here

It looks alright, but only from this direction. If I turn the camera a bit, this starts happening :

enter image description here

It seems as if my depth buffer is corrupt. I have it enabled, and it works well with other geometry.

Did anybody have a problem like this before? I don't even know what to search for. Thanks!

Edit :

My projection matrix setup :

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)
like image 902
qwertzguy Avatar asked Oct 19 '14 18:10

qwertzguy


1 Answers

Thank you all for your helpful comments. I found the issue, 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)), instead of once at renderer creation. I was under the impression that this was a global state, and thus wouldn't need to be reset everytime I render.

The end product looks like this, with no depth buffer problems :

enter image description here

Anyhow, hope this helps somebody.

like image 168
qwertzguy Avatar answered Oct 06 '22 00:10

qwertzguy