【发布时间】:2018-04-18 08:54:37
【问题描述】:
但是当我们绕过灌木丛时,两张图片中的一张的深度测试明显存在很大问题:
我尝试禁用深度测试,但情况更糟(背景灌木与前面的灌木重叠)。 我只是使用这段代码来渲染灌木丛(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();
我怎样才能修复这个错误并对这两个图像进行相关的深度测试?
【问题讨论】:
标签: c++ opengl alphablending depth-testing