Capturing a screenshot and and feed it to a renderTexture

Hi everyone,
I’ve been trying to upgrade some 3.17 projects to v4.0 and I’ve encountered the following problem. What the code is trying to achieve here is, capturing a screenshot of my app and then rendering it in another renderTexture, which is used to perform some free-hand drawing.
To explain why I need to do this, the initial setting is as follows:
Background Sprite → renderTexture used as blackboard which is transparent, except for the lines drawn with screen touches.

From this initial setting, with a button touch, I want to pass in another one which is kinda like this:
Different background Sprite → renderTexture fully opaque comprising of a “screenshot” of the drawing I made and the previous background

This way, when I “erase” from my renderTexture I can gradually reveal the second, different background Sprite.
The code for the first part, capturing a screen using a renderTexture is pretty straightforward:

RenderTexture *tex = RenderTexture::create(**int**(screenSize.width), **int**(screenSize.height), PixelFormat::RGBA8888);
tex->setPosition(Vec2(screenSize.width/2, screenSize.height/2));
tex->begin();
background->visit();
blackboard->visit();
tex->end();
tex->retain();

I was wondering what would be the best way to feed this image to the renderTexture which functions as a blackboard. The code already present, which was working fine in 3.17 was:

Image img = tex->newImage();
Texture2D tex2d = new Texture2D();
text2d->initWithImage(img)
Sprite* spr = Sprite::createWithTexture(tex2d);
spr->setAnchorPoint(Vec2(0,0));
spr->setPosition(Vec2(0, 0));

renderTexture->begin();
spr->visit();
renderTexture->end();

But this doesn’t seem to do anything at all in v4, leaving me with the “blackboard” renderTexture unchanged. Another, simpler way to do the same would seem to be

Sprite* spr = Sprite::createWithTexture(tex->getSprite()->getTexture());
  renderTexture()->begin();
  {
    spr->setAnchorPoint(Vec2(0,0));
    spr->setPosition(Vec2(0, 0));
    spr->visit();
  }
  renderTexture()->end();

Which however does not maintain the lines that I have previously drawn.
Could anyone hint me as to why this doesn’t work as in v3.17?

Do you have a minimal project that shows this issue? Even source files and any specific resources will suffice if they can be added to a project quickly. I’m curious if this issue has been fixed in this fork of cocos2d-x v4.

Hi, the sources are from a working game but I will try to write a minimal working test as soon as possible. I was thinking that maybe it had something to do with the order of the visit() calls, as I update the blackboard renderTexture continuously to show the hand-drawn lines. Thank you for the response, I will update when I manage to locate the issue more precisely.