Incpt.Mobis
Incpt.Mobis

Reputation: 199

iPhone - OpenGL ES 1.1 - Alpha Blend make texture wrong color

I'm newbie in OpenGL ES 1.1 for iPhone. Today, I tried to draw png texture on black background (the texture includes the alpha chanel) but the result is diference from source png file.

The Result on iPhone & Simulator:

enter image description here

Turn the light off:

enter image description here

It's should be (Brighter & more blur):

enter image description here

Source Texture file:

enter image description here

This is the source code I use:

//Setup:
glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glAlphaFunc(GL_GREATER,0.01);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
static const GLfloat light0Ambient[] = {1.0, 1.0, 1.0, 1.0};
static const GLfloat light0Diffuse[] = {1.0, 1.0, 1.0, 1.0};
static const GLfloat light0Position[] = {0.0, 0.0, 10.0};
glLightfv(GL_LIGHT0, GL_AMBIENT, (const GLfloat *)light0Ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, (const GLfloat *)light0Diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, (const GLfloat *)light0Position);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);

Drawing Code:

glBindTexture(GL_TEXTURE_2D, OYTextID);
glVertexPointer(3, GL_FLOAT, 0, GUI_Vertices);
glNormalPointer(GL_FLOAT, 0, GUI_Normals);
glTexCoordPointer(2, GL_FLOAT, 0, GUI_TexCoords);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

What is the issue make the color goes wrong ??

Thanks for reading, I appreciate any help. Best Regard & sorry for my English.

Upvotes: 1

Views: 1694

Answers (1)

brigadir
brigadir

Reputation: 6942

Looks like your PNG file has already premultiplied alpha. In this case you need to set

glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE instead of GL_SRC_ALPHA

Upvotes: 5

Related Questions