Hello ! I’m having a bit of a problem trying to use the CCRenderTexture class from Cocos2Dx 2.0 for the iPhone (which, as I understand it, is just a FBO class).
I have a class that derives from CCSprite. Within it, I’m trying to draw a texture to a CCrenderTexture and then save it for later. However, I noticed that the alpha values in my new texture seem to have been intensified. My new texture appears a bit more faded than the original, it only seems to effect pixels with an alpha less then 1.0.
Here is the code I am using:
@ CCRenderTexture* myRenderTexture = CCRenderTexture::create((int)getContentSize().width, (int)getContentSize().height); //set RenderTexture to same size as sprite
ccGLBlendFunc; //Is this where my problem is?
glBindTexture); //finalTexture is created before this code is run
long offset = &m_sQuad;
int diff = offsetof;
diff = offsetof;
diff = offsetof;
finalTexture = myRenderTexture~~>getSprite~~>getTexture; //Replace Final Texture with my new texture
As a test, I ran the above code 4 times in succession. Each time, the texture seemed to fade a bit more. But what I expect is it to look the same each time.
The next step I took was to replace ccGLBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) with ccGLBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA) It seemed to solve my problem, as the resulting texture looked the same no matter how many times I ran it. However, I am also running a custom fragment shader on this texture (shader not pictured and not running during this test) and it requires ccGLBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) to work correctly.
After some research, I tried replacing ccGLBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) with glBlendFuncSeparate(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA,GL_ONE, GL_SRC_ALPHA). I hoped this would maintain my alpha levels, while changing the color values. Unfortunately, this had the opposite effect and seemed to actually dull the alpha, causing the texture to darken.
Here is a picture with my three tests. This bikini bottom asset makes it easy to see the effect
Can someone tell me what I am doing wrong and what is causing these effects? Is it my BlendFunc? I need to be able to draw to a CCRenderTexture (or a FBO) several times in succession and I don’t want any undesired effects on the image. I also need to use my shaders… so ccGLBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA) doesn’t work…
Any help is appreciated! Thanks in advance!
Untitled-1.png (92.8 KB)