简体   繁体   English

在iOS上使用哪种OpenGL ES 1.1 alpha混合配置?

[英]Which OpenGL ES 1.1 alpha blending configuration to use on iOS?

If you want to achieve a blending of textures with transparency (like PNG) that is similar to UIKit, how do you configure OpenGL ES 1.1 appropriately? 如果要实现与UIKit类似的纹理与透明度的混合(如PNG),如何适当地配置OpenGL ES 1.1?

I found: 我发现:

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

But there is also: 但也有:

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);

You should use glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 您应该使用glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); . The other one has no respect for the alpha channel at all in this case, it will simply sum up the source and destination colours for you. 在这种情况下,另一个完全不尊重Alpha通道,它将为您简单地汇总源和目标颜色。

There is one thing you should note though. 不过,您应该注意一件事。 This will work great on colours but your destination alpha channel will not be correct. 这在颜色上效果很好,但是您的目标alpha通道将不正确。 In most cases you do not use it but if you wish to extract the image from buffer with the alpha channel as well you will need it, same goes for using FBO and reuse texture with transparency. 在大多数情况下,您不使用它,但是如果您也希望使用alpha通道从缓冲区中提取图像,则将需要它,使用FBO并以透明方式重用纹理也是如此。 In this case you should draw the alpha channel separately using glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE) . 在这种情况下,您应该使用glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE)单独绘制Alpha通道。 This means doubling the draw calls (at least I can't think of a better solution without shaders). 这意味着将绘图调用加倍(至少,没有着色器,我无法想到更好的解决方案)。 To draw to colour only you have to set glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE) and to draw alpha only use glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE) 若要仅绘制颜色,则必须设置glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE)并仅绘制alpha使用glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE)

To sum up: 总结一下:

glEnable(GL_BLEND);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//draw the scene
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);
//draw the scene
glDisable(GL_ALPHA_TEST);
glDisable(GL_BLEND);

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

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