OpenGL 和 GL_Blend 与 glDrawElements

OpenGL and GL_Blend with glDrawElements

通过添加glDepthFunc(GL_ALWAYS);

解决

我正在尝试使用 glDrawElements 在高度场上混合两个纹理。 Normalpointer 和 vertexpointer 数据相同,但两个纹理的 TexCoordPointer 不同。无论我尝试使用哪种 BlendFunc,尽管 texture_two 的大部分是透明的,但始终只有一个纹理可见。 glDrawElements 与 gl_blend 一起使用还是我做错了?

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_ADD);
glDepthFunc(GL_ALWAYS);

glNormalPointer(GL_FLOAT, 0, normals);
glVertexPointer(3, GL_FLOAT, 0, vertices);

glTexCoordPointer(2, GL_FLOAT, 0, texture_ind_one);
glBindTexture(GL_TEXTURE_2D, texture_one);
glDrawElements(GL_TRIANGLES, indicies_num, GL_UNSIGNED_INT, indices);

glNormalPointer(GL_FLOAT, 0, normals);
glVertexPointer(3, GL_FLOAT, 0, vertices);

glTexCoordPointer(2, GL_FLOAT, 0, texture_ind_two);
glBindTexture(GL_TEXTURE_2D, texture_two);
glDrawElements(GL_TRIANGLES, indicies_num, GL_UNSIGNED_INT, indices);

非常感谢!

您需要通过 glDepthFunc 使用其中包含 "equals" 的内容(可能是 GL_LEQUAL)设置适当的深度函数,因为您在同一深度绘制两次。

您也可以考虑在片段着色器中自己混合纹理。