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

China☆狼群 提交于 2020-01-23 16:46:20

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/10032036/iphone-opengl-es-1-1-alpha-blend-make-texture-wrong-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!