OpenGL ES depth buffer android, can't get to work

后端 未结 3 557
一向
一向 2021-01-06 01:14

I\'m unable to get the depth buffer working correctly on Android OpenGL ES 2.0. Regardless of what I do, the objects are always render in the order provided and completely i

相关标签:
3条回答
  • 2021-01-06 01:24

    Have you specified the buffer depth? This might be the solution to your problem.

    myGlSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    
    0 讨论(0)
  • 2021-01-06 01:42

    harism's comment was the correct answer. The below three functions can only be done once you have a rendering context. I put them in the onSurfaceCreated method and it works. You can also put them in the onDraw method if you change them during rendering.

    GLES20.glEnable( GLES20.GL_DEPTH_TEST );
    GLES20.glDepthFunc( GLES20.GL_LEQUAL );
    GLES20.glDepthMask( true );
    
    0 讨论(0)
  • 2021-01-06 01:42

    I had the same problem. I fixed it by using a 24-bit depth buffer instead of the default, which is 16 bits (so selecting a 16-bit depth buffer won't make any difference). I used

    myGlSurfaceView.setEGLConfigChooser(8,8,8,8,24,0);

    Incidentally I had the same problem, with effectively the same solution, on iOS (my code is a portable map renderer, so I need it to run on lots of platforms). The iOS fix was to call

    self.drawableDepthFormat = GLKViewDrawableDepthFormat24;

    in the init function of my GLKView-derived class.

    0 讨论(0)
提交回复
热议问题