iPhone – OpenGL texture mixing problem

I am using OpenGL ES to create a 2D application for the iPad, and I have some problems drawing transparent images.

I am using a fully transparent png- 24 images. I am also changing the color of some textures, these textures are white, and some areas are transparent or semi-transparent. Everything is normal.

But when I try to set the alpha value of one of the textures When, its effect is not normal. The color is too saturated, if the alpha value = 0, I will leave a white instead of a transparent image on a light gray background. When such a transparent image is on a dark image, the dark image becomes For the color similar to the color of the transparent image.

I have tried many parameter combinations of glTexEnvi and glBlendFunc but no success.

I don’t know much about OpenGL, so if anyone has Any suggestions, that would be great. If there are any details that can help me, please let me know.

Thank you.

This is the initialization of OpenGL

< /p>

 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glClearColor(1.0f, 1.0f, 1.0f, 1.0f);

glDisable(GL_DEPTH_TEST) ;

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); );
glEnable(GL_BLEND);

It sounds like you told OpenGL Your texture has premultiplied alpha, but it doesn’t actually.

What parameter glBlendFunc do you use?

More explanation of pre-multiplied alpha

I am using OpenGL ES to create a 2D application for the iPad, and I have some problems drawing transparent images.

I am using a fully transparent png-24 image. I am also changing the color of some textures, these textures are white, and some areas are transparent or semi-transparent. Everything is normal. < /p>

However, when I try to set the alpha value of one of the textures, its effect is not normal. The color is too saturated, if the alpha value = 0, I will leave white on a light gray background instead Transparent image. When such a transparent image is on a dark image, the dark image becomes a color similar to the color of the transparent image.

I have tried many parameter combinations of glTexEnvi and glBlendFunc without success.

I don’t know much about OpenGL, so if anyone has any suggestions, it would be great. If there are any details that can help me, please let me know.

Thank you.

p>

This is the initialization of OpenGL

 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glClearColor(1.0f, 1.0f, 1.0 f, 1.0f);

glDisable(GL_DEPTH_TEST);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_BLEND);

It sounds like you told OpenGL that your texture has premultiplied alpha, but it doesn’t.

What parameter glBlendFunc do you use?

More explanation of pre-multiplied alpha

Leave a Comment

Your email address will not be published.