繁体   English   中英

OpenGL ES 1.1-Alpha遮罩

[英]OpenGL ES 1.1 - alpha mask

我正在使用带有OpenFrameworks和OpenGL ES 1.1的iPad应用程序。 我需要显示带有Alpha通道的视频。 为了模拟它,我有一个RGB视频(没有任何alpha通道)和另一个仅包含alpha通道的视频(在每个RGB通道上,因此白色部分对应于可见部分,黑色部分对应于不可见部分)。 每个视频都是OpenGL纹理。

在OpenGL ES 1.1中没有着色器,因此我找到了此解决方案(在这里: OpenGL-具有多个纹理的蒙版 ):

glEnable(GL_BLEND);
// Use a simple blendfunc for drawing the background
glBlendFunc(GL_ONE, GL_ZERO);
// Draw entire background without masking
drawQuad(backgroundTexture);
// Next, we want a blendfunc that doesn't change the color of any pixels,
// but rather replaces the framebuffer alpha values with values based
// on the whiteness of the mask. In other words, if a pixel is white in the mask,
// then the corresponding framebuffer pixel's alpha will be set to 1.
glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ZERO);
// Now "draw" the mask (again, this doesn't produce a visible result, it just
// changes the alpha values in the framebuffer)
drawQuad(maskTexture);
// Finally, we want a blendfunc that makes the foreground visible only in
// areas with high alpha.
glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
drawQuad(foregroundTexture);

这正是我想要做的,但是glBlendFuncSeparate()在OpenGL ES 1.1(或iOS)上不存在。 我正在尝试使用glColorMask做到这一点,但我发现了这一点: 无法在OpenGL中正确使用遮罩

但是我认为它不是很好,因为他的蒙版纹理文件包含一个“真实”的Alpha通道,而不是我的。

我强烈建议您改为计算一个RGBA纹理。

这将既简单又快速(因为您每帧发送2个RGBA纹理-是的,您的RGB纹理实际上是由硬件以RGBA编码的,而A被忽略了)

glColorMask不会为您提供帮助,因为它只是说“完全打开或关闭此通道”。

glBlendFuncSeparate可以帮助您,但同样,它也不是一个好的解决方案:通过发送所需数据的两倍,您正在破坏(非常有限的)iphone带宽。

更新:

由于您使用的是OpenFrameworks,并且根据其源代码( https://github.com/openframeworks/openFrameworks/blob/master/libs/openFrameworks/gl/ofTexture.cpphttps://github.com/openframeworks/ openFrameworks / blob / master / libs / openFrameworks / video / ofVideoPlayer.cpp ):

  • 使用ofVideoPlayer :: setUseTexture(false),以便ofVideoPlayer :: update不会将数据上传到视频内存;
  • 使用ofVideoPlayer :: getPixels获取视频数据
  • 将结果插入RGBA纹理中(可以使用GL_RGBA ofTexture和ofTexture :: loadData)
  • 使用ofTexture :: Draw进行绘制(无论如何,这就是VideoPlayer所做的事情)

暂无
暂无

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

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