Projects > cpp > Issues > Bug #3365

We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.

Create Issue on Github

Specific picture drawn with "ping-pong" CCRenderTexture(s) “drifts” after each time of rendering

Bug #3365 [Closed]
godspeed1024 2013-12-09 08:56 . Updated over 9 years ago

Found the problem while working on an shader program for some special effects. The original image was drawn to one CCRenderTexture renderTexture0 and then the content of renderTexture0 was drawn into renderTexture1. And then draw back from renderTexture1 to renderTexture0, and over and over again…, just like a ping-pong buffer.
It is expected that the final content of renderTextureX should be the same with original image, but actually it makes some offset from the original image.What stranger, is that it seems to happen only on some specific picture(s), while most other pictures are OK.

The source code is reduced to an useless but enough-to-show-issue version, using only cocos2d-x build-in shader programs. And the picture with problem is also posted below.

bool HelloWorld::init()
    // 1. super init first
    if ( !CCLayer::init() )
        return false;

    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    CCTexture2D* sourceImage = CCTextureCache::sharedTextureCache()->addImage("pulsar0.png");
    CCSize size = sourceImage->getContentSize();
    CCRenderTexture* renderTexture0 = CCRenderTexture::create(size.width, size.height);
    CCRenderTexture* renderTexture1 = CCRenderTexture::create(size.width, size.height);

    renderTexture0->beginWithClear(0, 0, 0, 0);

    for (int i=0; i<100; i++)
        renderTexture1->beginWithClear(0, 0, 0, 0);
        renderTexture0->getSprite()->getTexture()->drawAtPoint(ccp(0, 0));

        renderTexture0->beginWithClear(0, 0, 0, 0);
        renderTexture1->getSprite()->getTexture()->drawAtPoint(ccp(0, 0));

    renderTexture0->setPosition(ccp(winSize.width/2, winSize.height/2));

    return true;



pulsar0.png - Original picture (45.1 kB) godspeed1024, 2013-12-09 08:56

bug0.png - Final content of render texture (49.5 kB) godspeed1024, 2013-12-09 08:56

godspeed1024 2013-12-09 08:59

The original picture:

Final content of render texture: 2014-10-08 02:52

Redmine issue system is closed, we are using github issue system instead.

This issue was moved to

Atom PDF

Start date:2013-12-09
Due date:
% Done:


Target version:-