2

My texture itself has a transparent background, and I would like to render it as-is.

glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glPushMatrix();

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glTranslatef(x, y, 0.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glVertexPointer(2, GL_FLOAT, 0, undoVertCoord);
glTexCoordPointer(2, GL_FLOAT, 0, undoTexCoord);
glBindTexture(GL_TEXTURE_2D, texUndo);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

The problem is with glColor4f. That function seems to overwrite the transparency of the texture, making parts opaque when it should be transparent. But if I feed glColor4f with alpha value of 0, the whole texture becomes transparent.

SO, can you render a texture that ignores glColor4f, rendering the texture as-is? Or in a way that doesn't affect the alpha values?

Some Noob Student
  • 14,186
  • 13
  • 65
  • 103
  • glColor4f should not 'overwrite' the texture's color. By default it modulates it, which means that with a glColor4f of (1,1,1,1), you will reproduce the texture colors exactly. If the transparency is breaking, then something else is wrong with your transparency unrelated to glColor. Are you certain that the alpha channel is being created correctly for your texture? – Tim Jul 25 '12 at 20:59

1 Answers1

8

What is your GL_TEXTURE_ENV_MODE set to? Try setting it to GL_REPLACE.

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
Michael
  • 57,169
  • 9
  • 80
  • 125