Android Opengl ES 2.0深度测试不';我不能正常工作

Android Opengl ES 2.0深度测试不';我不能正常工作,android,opengl-es,opengl-es-2.0,depth,Android,Opengl Es,Opengl Es 2.0,Depth,我正在学习OpenGLES2.0,并在Android上加载3d模型。我现在可以正确加载模型纹理,但在显示深度上有问题。当我把模型放在透视图中,模型的一部分被另一部分隐藏,我碰巧在另一个画之前画了一个或两个三角形,这就是我通过一些部分看到的 我尝试setEGLConfigChooser(8,8,8,8,16,0);和(8,8,8,8,24,0),但我的问题仍然是一样的,只是当我放置(8,8,8,8,24,0)并显示一个更好的定义时,但是当3d对象移动时,颜色会产生频闪效果,这让我感到不安 我还尝试

我正在学习OpenGLES2.0,并在Android上加载3d模型。我现在可以正确加载模型纹理,但在显示深度上有问题。当我把模型放在透视图中,模型的一部分被另一部分隐藏,我碰巧在另一个画之前画了一个或两个三角形,这就是我通过一些部分看到的

我尝试setEGLConfigChooser(8,8,8,8,16,0);和(8,8,8,8,24,0),但我的问题仍然是一样的,只是当我放置(8,8,8,8,24,0)并显示一个更好的定义时,但是当3d对象移动时,颜色会产生频闪效果,这让我感到不安

我还尝试了glDepthFunc函数(GL_LEQUAL);使用glEnable(GL_深度_测试),但这并不能解决我的问题

以下是问题的图片:

问题是:链接断了

好消息:链接断了

对不起,我的链接图片,我没有超过10的声誉,以张贴图片的问题

这是我的密码 我的人生观

public MyGLSurfaceView(Context context) {
    super(context);
    this.context = context;

    setEGLContextClientVersion(2);
    setEGLConfigChooser(true);

    //setZOrderOnTop(true);
    //setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    //setEGLConfigChooser(8, 8, 8, 8, 24, 0);
    //getHolder().setFormat(PixelFormat.RGBA_8888);

    mRenderer = new Renderer(context);
    setRenderer(mRenderer);
}
我的渲染器

 @Override
 public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);  
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glFrontFace(GL_CCW);
    glEnable(GL_DEPTH_TEST);

    mushroom = new Mushroom();

    textureProgram = new TextureShaderProgram(context);
    texture = TextureHelper.loadTexture(context, R.drawable.mushroom);
}

@Override
public void onSurfaceChanged(GL10 glUnused, int width, int height) {                
    glViewport(0, 0, width, height);

    MatrixHelper.perspectiveM(projectionMatrix, 45, (float) width
            / (float) height, 0f, 10f);
    setLookAtM(viewMatrix, 0, 0f, 1.2f, -10.2f, 0f, 0f, 0f, 0f, 1f, 0f);
}

@Override    
public void onDrawFrame(GL10 glUnused) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    multiplyMM(viewProjectionMatrix, 0, projectionMatrix, 0, viewMatrix, 0);

    glDepthFunc(GL_LEQUAL);
    //glDepthMask(true);

    positionMushroomInScene();
    textureProgram.useProgram();
    textureProgram.setUniforms(modelViewProjectionMatrix, texture);
    mushroom.bindData(textureProgram);

    mushroom.draw();
    //glDepthFunc(GL_LESS);
}

private void positionMushroomInScene() {
    setIdentityM(modelMatrix, 0);
    translateM(modelMatrix, 0, 0f, 0f, 5f);
    rotateM(modelMatrix, 0, -yRotation, 1f, 0f, 0f);
    rotateM(modelMatrix, 0, xRotation, 0f, 1f, 0f);
    multiplyMM(modelViewProjectionMatrix, 0, viewProjectionMatrix,
            0, modelMatrix, 0);
}
我的矩阵助手

public static void perspectiveM(float[] m, float yFovInDegrees, float aspect, float n, float f) {
    final float angleInRadians = (float) (yFovInDegrees * Math.PI / 180.0);
    final float a = (float) (1.0 / Math.tan(angleInRadians / 2.0));

    m[0] = a / aspect;
    m[1] = 0f;
    m[2] = 0f;
    m[3] = 0f;
    m[4] = 0f;
    m[5] = a;
    m[6] = 0f;
    m[7] = 0f;
    m[8] = 0f;
    m[9] = 0f;
    m[10] = -((f + n) / (f - n));
    m[11] = -1f;
    m[12] = 0f;
    m[13] = 0f;
    m[14] = -((2f * f * n) / (f - n));
    m[15] = 0f;
}

问题很可能与设置投影矩阵的方式有关:

MatrixHelper.perspectiveM(projectionMatrix, 45, (float) width
        / (float) height, 0f, 10f);
这个函数定义中的第四个参数是近平面。此值不应为0.0。它通常应该是距离的合理部分。选择理想值在某种程度上是一种折衷。
远/近
越大,深度精度越低。另一方面,如果将附近的值设置得太大,则可能会剪切掉您实际想要查看的闭合几何图形

远/近
的比例可能为100或1000,这通常会为您提供合理的深度精度,而不会出现不需要的前端剪裁。如果使用16位深度缓冲区,则需要比使用24位深度缓冲区时保守一点

出于您的目的,请尝试将
near
更改为0.1,然后看看它是如何为您工作的:

MatrixHelper.perspectiveM(projectionMatrix, 45, (float) width
        / (float) height, 0.1f, 10f);

看起来根本不像深度测试问题。可能只是剪辑,但我不是很确定。