Iphone – OpenGL texture blending problems

ipadiphoneopengl-es

I'm creating a 2d application for the iPad using OpenGL ES and having some issue drawing transparent images.

I'm using png-24 images with full transparency. I'm also changing the color of some of some textures, which are white with some areas transparent or semi-transparent. That all works fine.

When I try to set the alpha value of one of these textures, however, it's not working quite right. The colors are much too saturated, and if the alpha value = 0, i'm left with a white rather than transparent image over a light grey background. When such a transparent image is over a dark image, the dark image becomes a color similar to color of the transparent image.

I've tried a many parameter combinations of the glTexEnvi and glBlendFunc with no success.

I'm not very knowledgable about OpenGL, so if anyone has any suggestions, that would be great. Let me know if there are any details that would help.

Thanks.


Here is the initialization of OpenGL

    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);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnable(GL_BLEND);

Best Answer

Sounds like you told OpenGL your texture had premultiplied alpha, but it actually doesn't.

What parameters are you using for glBlendFunc?

More explanation of pre-multiplied alpha

Related Topic