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\$
7
  • \$\begingroup\$ How have you configured depth writes (eg. glDepthMask)? \$\endgroup\$
    – DMGregory
    Commented Sep 7, 2019 at 2:43
  • \$\begingroup\$ @DMGregory According to that link, that is enabled by default. I have not turned it off. \$\endgroup\$ Commented Sep 7, 2019 at 2:44
  • 1
    \$\begingroup\$ Can you show us how you define the output you're rendering into, including its depth buffer? \$\endgroup\$
    – DMGregory
    Commented Sep 7, 2019 at 2:55
  • \$\begingroup\$ It seems to me like you don't have a depth buffer requested during surface creation. \$\endgroup\$
    – Ocelot
    Commented Sep 7, 2019 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
    Commented Sep 7, 2019 at 11:11

1 Answer 1

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\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .