Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone opengl es alpha-blending. I have black color in edge

I am developing iPhone game. I have the below Source image to draw it to the background. The Source image has alpha 0x00 and gradation around edge and the background's alpha is 0xff. When I draw the source image to the background, I have black color like you could see the Result image. I am using OpenGL ES glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) method. I have changed every possible arguments, but every time it is not moved.

Why do I have the black color in the edge of the source image? What is the problem? Does not every games in iphone use gradation?

Do I need to make the source image with out gradation?

Does anyone know the solution?

Source image :

alt text

Result image :

alt text

like image 435
mooongcle Avatar asked Jan 22 '11 23:01

mooongcle


1 Answers

Does your image have pre-multiplied alpha? Then you should be using

glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

Here is some explanations of what it is.

Note: I rewrote the answer after doing some research. The article rotoglup mentioned has some insight on what's going on and it makes more sense then my original formula. I also tried to see what other people are using in their code and it looks like this formula is the most used one. It's amazing how such a basic thing in 3D graphics as alpha blending can be so controversial and everyone seems to reinvent the wheel and come up with their own solutions.

like image 171
detunized Avatar answered Nov 06 '22 10:11

detunized