user3049681
user3049681

Reputation: 407

OpenGL and GL_Blend with glDrawElements

Solved by adding glDepthFunc(GL_ALWAYS);

I'm trying to blend two textures on a heightfield with glDrawElements. Normalpointer and vertexpointer data are the same but the TexCoordPointer are different for the two textures. No matter which BlendFunc I try there's always only one of the textures visible although large parts of texture_two are transparent. Does glDrawElements work with gl_blend or am I doing it wrong?

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);

Thank you very much!

Upvotes: 0

Views: 351

Answers (1)

Gerard
Gerard

Reputation: 851

You need to set an appropriate depth function via glDepthFunc using something that has "equals" in it (probably GL_LEQUAL), since you are drawing twice at the same depth.

You can also consider blending the textures yourself inside a fragment shader.

Upvotes: 3

Related Questions