简体   繁体   English

iPhone opengl es alpha-blending。 我的边缘有黑色

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

I am developing iPhone game. 我正在开发iPhone游戏。 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. 源图像具有alpha 0x00和边缘周围的渐变,背景的alpha为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. 我正在使用OpenGL ES glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)方法。 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? iPhone中的每个游戏都不会使用渐变吗?

Do I need to make the source image with out gradation? 我是否需要制作渐变的源图像?

Does anyone know the solution? 有谁知道解决方案?

Source image : 来源图片:

替代文字

Result image : 结果图片:

替代文字

Does your image have pre-multiplied alpha? 你的图像是否预先乘以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. 所提到的文章rotoglup对正在发生的事情有一些了解,它比我原来的公式更有意义。 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. 令人惊讶的是,像3D混合这样的3D图形基本功能如此具有争议性,每个人似乎都在重新发明轮子并提出自己的解决方案。

One way this can occur is if you haven't correctly set your glTexParameteri for minification and magnification filters correctly, along with your clamp method. 出现这种情况的一种方法是,如果没有正确设置glTexParameteri以进行缩小和放大滤镜,以及钳制方法。 See Adam Redwood's comment here . 见亚当红木的评论在这里 Note issues of power-of-two textures, texture boundaries etc. may also come into play. 注意两个纹理纹理,纹理边界等问题也可能起作用。

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );

Just check the view on which you are drawing is opaque or not. 只需检查您正在绘制的视图是否不透明。 set opaque property to false 将opaque属性设置为false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM