iPhone-OpenGL ES 1.1-Alpha Blend使纹理颜色错误 [英] iPhone - OpenGL ES 1.1 - Alpha Blend make texture wrong color

查看:98
本文介绍了iPhone-OpenGL ES 1.1-Alpha Blend使纹理颜色错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是适用于iPhone的OpenGL ES 1.1的新手.今天,我尝试在黑色背景上绘制png纹理(该纹理包括alpha chanel),但结果与源png文件有所不同.

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.

iPhone上的结果模拟器:

The Result on iPhone & Simulator:

关闭灯:

应该是(更亮和更模糊):

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

源纹理文件:

这是我使用的源代码:

//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);

绘图代码:

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.

推荐答案

好像您的PNG文件已经预乘alpha.在这种情况下,您需要设置

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

这篇关于iPhone-OpenGL ES 1.1-Alpha Blend使纹理颜色错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆