Issue using two RenderTexture

Hi,

I have an issue with RenderTexture. I’ll try to explain it clearly.

If I draw a parent layer into a RenderTexture, then draw the RenderTexture, all works perfectly.
But if I add a child layer to this layer, the simple fact of calling “_renderTexture->beginWithClear” and “_renderTexture->end” in the visit method of the child layer stretch the content of that child layer. Event if I didn’t draw anything into this RenderTexture and didn’t use it.
However everything is okay if the DesignResolutionSize is the same as the window’s size.

Thanks in advance for the help :slight_smile:

Here is a simple code to reproduce this issue.

In AppDelegate.cpp :

bool AppDelegate::applicationDidFinishLaunching() 
{
    auto director = Director::getInstance();
    auto eglView = director->getOpenGLView();
    if(!eglView) {
        eglView = GLView::createWithRect("Game", Rect(0,0,960, 540));
        director->setOpenGLView(eglView);
    }
    director->setProjection(ccDirectorProjection::_2D);
    eglView->setDesignResolutionSize(480, 270, ResolutionPolicy::NO_BORDER);
    director->setAnimationInterval(1.0 / 60.0);
    auto scene = Scene::createScene();
    scene ->addChild(ParentLayer::create());
    director->runWithScene(scene);
    return true;
}

The visit methods :

void ParentLayer::visit(Renderer* renderer, const kmMat4 &parentTransform, bool parentTransformUpdated)
{	
    RenderTexture* _renderTexture = RenderTexture::create(Director::getInstance()->getWinSize().width, Director::getInstance()->getWinSize().height);
    Color3B c1 = Color3B::BLACK;
    _renderTexture->beginWithClear(c1.r, c1.g, c1.b, 255.0);
    Layer::visit(renderer, parentTransform, parentTransformUpdated);
    _renderTexture->end();
    _renderTexture->visit(renderer, parentTransform, parentTransformUpdated);
}

void ChildLayer::visit(Renderer* renderer, const kmMat4 &parentTransform, bool parentTransformUpdated)
{	
    RenderTexture* _renderTexture = RenderTexture::create(Director::getInstance()->getWinSize().width, Director::getInstance()->getWinSize().height);
    Color3B c1 = Color3B::BLACK;
    _renderTexture->beginWithClear(c1.r, c1.g, c1.b, 255.0);
    _renderTexture->end();
    Layer::visit(renderer, parentTransform, parentTransformUpdated);
}

I fixed stretching problems by calling setKeepMatrix(true) on the render texture.

Thank you for your answer.
Unfortunatly that didn’t fix my issue…