使用两个透明图像的深度测试会导致奇怪的伪像

Depth test with two transparent images causes strange artifacts

我正在渲染一个由两个相同图像交叉组成的灌木丛,如下图所示:

但是当我们绕过灌木丛时,两张图片中的一张在深度测试中有明显的大问题:

我尝试禁用深度测试,但情况更糟(背景灌木与前面的灌木重叠)。 我只是使用此代码来渲染灌木丛(使用 m_tex 和 m_vertex 文件中加载的灌木丛坐标):

//Scene initialisation
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

//Then we render objects one per one
glBindTexture(GL_TEXTURE_2D, m_texture);
glBegin(GL_QUADS);
    glTexCoord2d(m_tex[0][0], m_tex[0][1]); glVertex3d(m_vertex[0][0] + coordinates[0], m_vertex[0][1] + coordinates[1], m_vertex[0][2] + coordinates[2]);
    glTexCoord2d(m_tex[1][0], m_tex[1][1]); glVertex3d(m_vertex[1][0] + coordinates[0], m_vertex[1][1] + coordinates[1], m_vertex[1][2] + coordinates[2]);
    glTexCoord2d(m_tex[2][0], m_tex[2][1]); glVertex3d(m_vertex[2][0] + coordinates[0], m_vertex[2][1] + coordinates[1], m_vertex[2][2] + coordinates[2]);
    glTexCoord2d(m_tex[3][0], m_tex[3][1]); glVertex3d(m_vertex[3][0] + coordinates[0], m_vertex[3][1] + coordinates[1], m_vertex[3][2] + coordinates[2]);
glEnd();

我如何设法修复此错误并使用两张图像进行相关的深度测试?

首先,立即模式(glBegin()、glEnd() 等)现在已弃用,所以我建议避免使用它,尤其是如果您正在学习 OpenGL现在(查看文档 here)。

除此之外,您应该 post 一个 完整示例 (看看 here),因为有多种因素会导致这些影响你描述了(你的场景是如何初始化的?你如何加载纹理?它们真的是 RGBA​​ 吗?等等)。