2012-08-04 76 views
1

我不明白透明度/ alpa如何與CCRenderTexture一起使用。CCRenderTexture(alpha)beginWithClear透明白色

有了這段代碼,我期望在紅色ColorLayer(透明度適用於CCLayerColor)上有半透明的白色。我得到的是完整的白色。

此代碼僅添加到HelloWorldLayer init方法末尾的默認模板中。

CCLayerColor * lc = [CCLayerColor layerWithColor:ccc4(255.0f, 0.0f, 0.0f, 125.0f)]; 
    [self addChild:lc]; 

    CCRenderTexture * rt = [CCRenderTexture renderTextureWithWidth:480.0f 
                  height:320.0f]; 
    [self addChild:rt]; 
    rt.position = ccp(240.0f,160.0f); 

    [rt beginWithClear:1.0f g:1.0f b:1.0f a:0.5f]; 

    [rt end]; 

如果我變成黑色我得到半透明的黑色:

[rt beginWithClear:0.0f g:0.0f b:0.0f a:0.5f]; 

隨着阿爾法0.0F和綠色1.0我得到綠色 - 本來期望的透明層.. [RT beginWithClear: 0.0fg:1.0fb:0.0fa:0.0F];

IST在那個RT我不能老是在片段着色器與白色繪製的透明度,真正的問題:

gl_FragColor = vec4(1.0, 1.0, 1.0, 0.5); 

結果完全白..

任何想法?

回答

4

試試:

[renderTexture.sprite setBlendFunc:(ccBlendFunc){GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}];