I have a CCRenderTexture that is filled with a sprite when the scene is loaded, as follows,

canvas = CCRenderTexture::create(this->getContentSize().width, this->getContentSize().height);
canvas->beginWithClear(0.0, 0.0, 0.0, 0);

The above code is written within a class, which derives from CCSprite (Hence this).

Then, in another function applyShader(), I create a sprite named splat, from the texture of CCRenderTexture *canvas. Thus splat will contain the whole texture of canvas.

Now I apply a custom fragment shader to the splat by calling the function splat->renderShader(), which will modify some small portion of the whole texture.

Then I draw the modified texture back to the CCRenderTexture *canvas.

Hence, applyShader() will * take a texture from CCRenderTexture, * create a sprite based on it, * apply a fragment shader to it * and draw the modified texture back to CCRenderTexture.

This applyShader() will be called repetitively and its code is as follows:

splat = Splat::createWithTexture(art->canvas->getSprite()->getTexture());

My shader code is (nothing fancy)

precision mediump float;

varying vec2 v_texCoord;
uniform sampler2D u_texture;
uniform sampler2D u_colorRampTexture;
uniform float params[5];

void main() {
    gl_FragColor = texture2D(u_texture, v_texCoord);

So, with the above code I expect the original sprite this to get rendered over and over again without any visual changes. But on each call to applyShader(), the texture is getting stretched a little and the stretched image is getting rendered. After some 10 calls, the image gets so distorted.

Can someone please tell me where I am going wrong?

Thanks :-)

PS: All code shown here is partial, not complete code.

Edit: Adding Screens Render Texture Problem

Update: The problem has nothing to do with shaders it seems. It happens even when I dont call renderShader(). The actual lines of code is:

splat = Splat::createWithTexture(art->canvas->getSprite()->getTexture());
splat->setPosition( ccp( art->getContentSize().width * 0.5, art->getContentSize().height * 0.5 ) );
  • 1
    \$\begingroup\$ Can you include video or images of what's happening? It may help to spot the issue. \$\endgroup\$ – MichaelHouse Jun 13 '13 at 17:18

Not a solution, but something that improves the situation


Since the problem appears to be the Splat which gets scaled up a bit for some reason, I am trying to scale (down) it back. But 0.995f doesnt give exact results, I am in search for a magic number between 0.994 and 0.995 !!!


I don't know if you already solved this or not, but try this:

  • 3
    \$\begingroup\$ Could you add anything about why someone should do this? Ideally, readers should be able to understand what's significant about his, and when they might like to use it. \$\endgroup\$ – doppelgreener Oct 6 '13 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.