2012-07-26 214 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