iPhone OpenGL ES不正确的Alpha混合 [英] iPhone OpenGL ES incorrect alpha blending

查看:100
本文介绍了iPhone OpenGL ES不正确的Alpha混合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iPhone上使用openGL ES时,alpha混合结果不正确.

I have a problem with incorrect alpha blending results with openGL ES on iPhone.

这是我创建纹理对象的代码:

This is my code for creating texture object:

glGenTextures(1, &tex_name);
glBindTexture(GL_TEXTURE_2D, tex_name);
glTextImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_width, tex_height, GL_RGBA, GL_UNSIGNED_BYTE, tex_data);

'tex_data'从zlib打包的原始RGBA8888数据加载.它已按需加载,直到我已通过调试器进行了检查.

'tex_data' is loaded from raw RGBA8888 data packed with zlib. It loads as it should, wich i've checked with a debugger.

这是我在渲染之前设置纹理的代码:

This is my code for setting up texture before rendering:

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glBindTexture(GL_TEXTURE_2D, tex_name);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

我已上传了我期望的示例以及在这里获得的示例:

I've uploaded a sample of what I've expected and what I've got here: sample . In the sample most of the texture in the bottom is pitch-black with 70% opacity. However openGL renders it as gray. This problem affects all of my textures I use blend with.

我已经使用OGLES PVRVFrame在Windows上测试了代码,结果符合预期:黑色呈现为黑色.

I've tested the code on windows with use of OGLES PVRVFrame and the results are as expected: black is rendered as black.

推荐答案

发现了问题.我忘记将EAGLView的CAEAGLLayer的opaque属性设置为YES.

Found the problem. I've forgot to set opaque property of CAEAGLLayer of EAGLView to YES.

这篇关于iPhone OpenGL ES不正确的Alpha混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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