0

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!

user3049681
  • 397
  • 4
  • 12
  • 1
    Try setting a depth function via `glDepthFunc` using something that has "equals" in it, since you are drawing twice with the same depth. If that doesn't work, include the depth function at least in your given code example. – Gerard May 17 '15 at 15:36
  • Thanks!!! I used glDepthFunc(GL_ALWAYS); and it works perfectly now! – user3049681 May 17 '15 at 15:47
  • Posted a slightly modified version of my comment as an answer. – Gerard May 17 '15 at 15:52

1 Answers1

3

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.

Gerard
  • 831
  • 6
  • 15