iPhone opengl es alpha-blending。边缘有黑色 [英] iPhone opengl es alpha-blending. I have black color in edge

查看:174
本文介绍了iPhone opengl es alpha-blending。边缘有黑色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发iPhone游戏。我有下面的源图像将其绘制到背景。源图像具有alpha 0x00和边缘周围的渐变,背景的alpha为0xff。当我将源图像绘制到背景时,我会看到黑色,就像您可以看到结果图像一样。我正在使用OpenGL ES glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)方法。我已经改变了所有可能的论点,但每次都没有被移动。

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.

为什么我在源图像的边缘有黑色?问题是什么? iPhone中的每个游戏都不会使用渐变吗?

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?

源图片:

结果图片:

推荐答案

你的图像是否预先乘以alpha?然后你应该使用

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

glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

这里是对它的解释。

注意:我做了一些研究后重写了答案。提到的文章 rotoglup 对正在发生的事情有一些了解,它比我原来的公式更有意义。我还试着看看其他人在他们的代码中使用了什么,看起来这个公式是最常用的。令人惊讶的是,3D图形中像阿尔法混合这样的基本内容如此具有争议性,每个人似乎都在重新发明轮子并提出自己的解决方案。

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.

这篇关于iPhone opengl es alpha-blending。边缘有黑色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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