3.0-beta2 Saving screen with RenderTexture problem

I tried taking screenshot of some nodes by calling their visit() method between begin() and end() methods of RenderTexture instance.

I got an unexpected result with 3.0-beta2 while the same code 3.0alpha0 works normal.

bool HelloWorld::init()
{

    if ( !Layer::init() )  return false;

    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();
    
    
    auto label = LabelTTF::create("Hello World", "Arial", 24);
    label->setPosition(Point(origin.x + visibleSize.width/2,
                             origin.y + visibleSize.height - label->getContentSize().height));
    this->addChild(label, 1);
    

    auto sprite = Sprite::create("HelloWorld.png");
    sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    this->addChild(sprite, 0);
    
    

    RenderTexture *rendTex = RenderTexture::create(visibleSize.width, visibleSize.height );
    
    rendTex->beginWithClear(0.3f, 0.56f, 1.0f, 1.0f);
    
    label->visit();
    sprite->visit();
    rendTex->end();
    
    rendTex->saveToFile("test.jpg", Image::Format::JPG);
    
    CCLOG("Saved to %s", FileUtils::getInstance()->getWritablePath().c_str() );
    
    return true;
}


render_texture_3-0-beta2-problem.png (15.1 KB)

Thanks, I created a bug for it. We’ll try to fix it for our next release.
http://cocos2d-x.org/issues/3896

Thank you, the issue has been fixed on pr: https://github.com/cocos2d/cocos2d-x/pull/5365
However, because of new renderer, save renderTexture to file cannot be used like this.

rendTex->beginWithClear(0.3f, 0.56f, 1.0f, 1.0f);
label->visit();
sprite->visit();
rendTex->end();

this function call will only send renderCommand to renderer, the actual rendering happens when we call renderer->render(); So the function rendTex->saveToFile("test.jpg", Image::Format::JPG); can be called the next frame.

we will create a doc to show How to use render Texture. issue link is http://cocos2d-x.org/issues/4124

@dabingnn
hi,How to use render Texture?