OpenGL ES 中的遮罩
阅读 Nehe 上的 #20 教程和这里关于遮罩的问题,我使用黑白图像和不透明图像实现了遮罩,但是结果完全不是预期的(我在 iPhone 上使用 OpenGL ES 1,所以不能使用着色器)。
源+掩码=结果
从结果图片中可以看出,蒙版上的白色不是透明的,黑色不是源颜色,而是白色(!) 这是我用来渲染它的源代码:
// we render from one big texture using coordinates
// so changing rectangle will change the drawn image
_pressedFrame = maskRect;
glBlendFunc(GL_DST_COLOR,GL_ZERO);
[super render:sender];
_pressedFrame = normalRect;
glBlendFunc(GL_ONE,GL_ONE);
[super render:sender];
感谢您的帮助!
reading #20 tutorial on Nehe and a question here about masking, I implemented masking using b/w image and opaque image, however the result is completely not what is expected (I'm using OpenGL ES 1 on iPhone, so can't use shaders).
Source+Mask=Result
As can be seen on the result picture what is white on mask isn't transparent and what is black isn't source color, but white (!)
Here is the source code I use to render it:
// we render from one big texture using coordinates
// so changing rectangle will change the drawn image
_pressedFrame = maskRect;
glBlendFunc(GL_DST_COLOR,GL_ZERO);
[super render:sender];
_pressedFrame = normalRect;
glBlendFunc(GL_ONE,GL_ONE);
[super render:sender];
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了使 NeHe 教程中的技术正常工作,源图像的背景(即遮罩图像为白色的任何地方)需要为全黑。尽管从第一张图像中不清楚来源到底是什么,但我怀疑最终图像中变亮的地方并不是黑色的。
然而,在 OpenGL ES 1.1 中不需要以这种方式进行遮罩。您可以使用多重纹理在单通道中渲染带有 alpha 蒙版的图像。此外,如果您的蒙版和图像始终绘制在一起,那么您最好将它们烘焙成单个 RGBA 纹理,无需多重纹理。
For the technique from the NeHe tutorial to work correctly, the background of your source image (i.e. anywhere where the mask image is white) needs to be full black. Although it’s not obvious from your first image exactly what the source is, I suspect that it isn’t black in the places that are brightening in the final image.
However, doing masking this way isn’t necessary in OpenGL ES 1.1. You can render an image with an alpha mask in a single pass using multitexturing. Furthermore, if your mask and your image are always drawn together, you’re better off just baking them into a single RGBA texture—no multitexturing required.