android opengl深度测试失败

标签 android opengl-es android-emulator

我在 Android 模拟器中遇到问题,我使用 gles 1 渲染纹理立方体,并在边框中显示背面:

Problem image

我的深度测试设置是:

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);  // Set color's clear-value to black
    gl.glClearDepthf(1.0f);            // Set depth's clear-value to farthest
    gl.glEnable(GL10.GL_DEPTH_TEST);   // Enables depth-buffer for hidden surface removal
    gl.glDepthFunc(GL10.GL_LEQUAL);    // The type of depth testing to do
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);  // nice perspective view
    gl.glShadeModel(GL10.GL_SMOOTH);   // Enable smooth shading of color
    gl.glDisable(GL10.GL_DITHER);      // Disable dithering for better performance

我的观点:

public void onSurfaceChanged(GL10 gl, int width, int height) {
    if (height == 0) height = 1;   // To prevent divide by zero
    float aspect = (float)width / height;

    // Set the viewport (display area) to cover the entire window
    gl.glViewport(0, 0, width, height);

    // Setup perspective projection, with aspect ratio matches viewport
    gl.glMatrixMode(GL10.GL_PROJECTION); // Select projection matrix
    gl.glLoadIdentity();                 // Reset projection matrix
    // Use perspective projection         
    GLU.gluPerspective(gl, 45, aspect, 0.1f, 1000.f);

    gl.glMatrixMode(GL10.GL_MODELVIEW);  // Select model-view matrix
    gl.glLoadIdentity();                 // Reset

    // You OpenGL|ES display re-sizing code here
    // ......
}

最佳答案

看来您的深度缓冲区精度可能不够,因此面有些重叠。

如果可能的话,我建议减小深度范围,要么增加近平面(比如 1),要么减小远平面。平面之间的距离越远,现有范围的精度就越低。

关于android opengl深度测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12145420/

相关文章:

android - 仅在 HTC Desire HD 上从主题设置文本颜色失败

opengl-es - OpenGL ES 片段着色器显然不可能返回白色

scripting - adb emu Kill - 等待模拟器被完全杀死

android - Opengl - glGenTextures 错误 1280

iphone - 在 GPUImage 中实现一个简单的自适应阈值

Android outofmemory 错误位图大小超过 2.3.3 中的 vm 预算

java - Gradle 未在模拟器上构建应用程序

android - 禁用标签之间的滑动

java - setOnClickListener 匿名类?

android - 允许用户撤消 "don' t 再次询问”?