iPhone OpenGL ES incorrect alpha blending

2019-05-07 02:03发布

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' 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.

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

2条回答
够拽才男人
2楼-- · 2019-05-07 02:37

Will this help? glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA) I think this just blends the two instead of blending both against the background.

Sorry if I don't understand.

查看更多
We Are One
3楼-- · 2019-05-07 02:49

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

查看更多
登录 后发表回答