ios - OpenGL ES 1.1 - Alpha 蒙版

标签 ios opengl-es openframeworks

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

在 OpenGL ES 1.1 中没有着色器,所以我找到了这个解决方案(此处:OpenGL - mask with multiple textures):

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 来做到这一点,我发现了这个:Can't get masking to work correctly with OpenGL

但它不起作用,我猜是因为他的蒙版纹理文件包含一个“真正的”Alpha channel ,而不是我的。

最佳答案

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

这会更容易、更快(因为您每帧发送 2 个 RGBA 纹理 - 是的,您的 RGB 纹理实际上由硬件以 RGBA 进行编码,并且 A 被忽略)

glColorMask 不会帮助你,因为它只是说“完全打开或关闭这个 channel ”。

如果你有的话,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 进行绘制(这就是 ofVideoPlayer 所做的事情)

关于ios - OpenGL ES 1.1 - Alpha 蒙版,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11666825/

相关文章:

ios - UIModalTransitionStylePartialCurl 在 iOS 8 上消失

python - Pygame 窗口在 Mac 上不接收键盘事件

android - 在 eglSwapBuffers 之后保留后台缓冲区内容

.net - 是否有用于像 Processing 或 OpenFrameworks 这样的艺术编码的 .Net 库?

ios - 如何将大量数据加载到 CoreData 中

ios - 如何修复 xcode 中的这些错误?

Android OpenGL ES GL10 或 GL11

android - 在 Android 中操作自定义 GLSurfaceView

opencv - Openframeworks 上图像处理的类型差异

c++ - 在我的 C++ OpenFrameworks 项目中未定义对 wpa_ctrl 函数的引用。需要帮助集成这个 c 库