2012-07-26 52 views
0

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

在的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通道,而不是我的。

+0

glColorAlpha不存在;你的意思是glColorMask? – Calvin1602 2012-07-26 10:05:51

+0

哦,是的,对不起,我刚刚纠正。 – user1554162 2012-07-26 10:07:47

+0

alpha通道从哪里来? – Calvin1602 2012-07-26 10:22:29

回答

1

我强烈建议您计算一个单一的RGBA纹理。

这将是双方更容易和更快的(因为你发送2个RGBA纹理每一帧 - 是的,你的RGB纹理实际上是由硬件的RGBA编码,和A被忽略)

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

glBlendFuncSeparate可以帮助你,如果你有它,但它又不是一个好的解决方案:通过发送两倍的数据来破坏你的(非常有限的)iphone带宽。

UPDATE:

由于您使用了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(假),这样ofVideoPlayer ::更新拿下将数据上传到视频内存;
  • 获取与ofVideoPlayer ::的getPixels
  • 交织的结果在RGBA纹理视频数据(你可以使用一个GL_RGBA ofTexture和ofTexture :: loadData)
  • 绘制使用ofTexture ::抽奖(这是ofVideoPlayer做什么无论如何)
+0

问题是我的纹理是视频,我们选择了H.264编解码器,因为文件比动画编解码器文件轻得多......而且这将是唯一的“沉重”过程,所以我想它应该可以工作,即使在iPad上,你不觉得吗? – user1554162 2012-07-26 10:17:27

+0

您必须将视频发送到OpenGL,并在某处放置glTexSubImage2D,对吗?或者是视频直接解码到视频内存? – Calvin1602 2012-07-26 10:19:36

+0

我使用的是OpenFrameworks的VideoPlayer类:http://www.openframeworks.cc/documentation/video/ofVideoPlayer.html#draw。它通过quicktime加载到电影文件中,所以我想视频在视频内存中被解码,我错了吗? – user1554162 2012-07-26 10:25:47