1
\$\begingroup\$

I have a simple OpenGL program that renders terrain with a texture. It exhibits some strange behaviors (see video) that look similar to depth test issues. However, I have already enabled depth test. Where else can I look to solve this problem?

https://www.youtube.com/watch?v=WHTFa3tMSyQ

This is the relevant setup code

glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

... VBO and texture setup ..

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

projectionMatrix = glm::frustum(-2.0, 2.0, -2.0, 2.0, 1.0, 10000.0);

... rendering stuff ...

glFlush();
swapEGLBuffers();
\$\endgroup\$
  • \$\begingroup\$ How have you configured depth writes (eg. glDepthMask)? \$\endgroup\$ – DMGregory Sep 7 '19 at 2:43
  • \$\begingroup\$ @DMGregory According to that link, that is enabled by default. I have not turned it off. \$\endgroup\$ – user8908459 Sep 7 '19 at 2:44
  • 1
    \$\begingroup\$ Can you show us how you define the output you're rendering into, including its depth buffer? \$\endgroup\$ – DMGregory Sep 7 '19 at 2:55
  • \$\begingroup\$ It seems to me like you don't have a depth buffer requested during surface creation. \$\endgroup\$ – Ocelot Sep 7 '19 at 3:03
  • 1
    \$\begingroup\$ If you've solved your problem, then you're in a better position to share the code that solved it. It's 100% OK to answer your own questions here. :) \$\endgroup\$ – DMGregory Sep 7 '19 at 11:11
1
\$\begingroup\$

The problem was that I did not request a depth buffer in my EGL config. The solution was to add EGL_DEPTH_SIZE to my requested EGL configuration:

So this:

EGLint attrib_list[]= { EGL_RED_SIZE,        8,
                        EGL_GREEN_SIZE,      8,
                        EGL_BLUE_SIZE,       8,
                        EGL_SURFACE_TYPE,    EGL_WINDOW_BIT,
                        EGL_RENDERABLE_TYPE, 0,
                        EGL_NONE};

Became this:

EGLint attrib_list[]= { EGL_RED_SIZE,        8,
                        EGL_GREEN_SIZE,      8,
                        EGL_BLUE_SIZE,       8,
                        EGL_SURFACE_TYPE,    EGL_WINDOW_BIT,
                        EGL_RENDERABLE_TYPE, 0,
                        EGL_DEPTH_SIZE, 24,
                        EGL_NONE};

This answer on stackoverflow helped: https://stackoverflow.com/questions/13349714/messed-up-opengl-depth-buffer

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.