简体   繁体   中英

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:

在此处输入图像描述

Turn the light off:

在此处输入图像描述

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

在此处输入图像描述

Source Texture file:

在此处输入图像描述

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM