3.0 beta 2 RenderTexture stretching

Appreciate your reaction!

Unfortunately this doesn’t fix my issue. Now it blurs the rendered sprites and it seems they stretch away from the center to the edges after repeated visits . Please find attached screenshot.

Thanks!

1 Like

Please find the below the problematic part of my coloring book source code that I’m trying to report to you. Just schedule the following code to be executed repeatedly:

if(mainTarget == NULL) {

mainTarget = RenderTexture::create(theSprite->getBoundingBox().size.width, theSprite->getBoundingBox().size.height, Texture2D::PixelFormat::RGBA8888);
mainTarget->setPosition(Vec2(theSprite->getBoundingBox().size.width * 0.5f, theSprite->getBoundingBox().size.height * 0.5f));
mainTarget->retain();

this->addChild(mainTarget);

mainTarget->begin();
theSprite->visit();

}
else {
mainTarget->begin();
mainTarget->getSprite()->setPosition(Vec2(theSprite->getBoundingBox().size.width * 0.5f, theSprite->getBoundingBox().size.height * 0.5f));
mainTarget->getSprite()->visit();
}
mainTarget->end();

Please find the output in a movie at (sorry about the quality reduced by dropbox):

You can find the code integrated in a scene also at the following address:

Let me know if you need further details!

Thanks!

This problem is also observed when using TransitionCrossFade between two scenes. At the end of animation the screen contents jump slightly. On closer inspection the pattern is the same as in Grif’s screenshot above. The image is slightly wider during the animation along these 4 lines. TransitionCrossFade uses RenderTexture internally, so it looks like the bug is in RenderTexture.

cocos2d-x 3.8.1
Applying any of the fixes suggested in this thread did not help.

This helped me though. Thanks! :smile:

Is there any fix for this bug?

This very well may be a hack and probably doesn’t work well if the sprite to render is a child of parent node(s) or if the scene position has changes, or you want to render out from a camera. It may also not work for others, but it appears to have fixed the issue of “bleeding” texture rendering when doing a ping-pong rendering from RenderTexture_A into RenderTexture_B and vice versa over many frames.

// CCRenderTexture.cpp : 568
director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
Mat4 orthoMatrix;
Mat4::createOrthographicOffCenter(0, texSize.width, 0, texSize.height, -1024, 1024, &orthoMatrix);
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, orthoMatrix);

My guess is that there are some precision or slight math issues related to setting up the projection for the render texture. Because it seems there are no real issues outside of this ping-pong drawing render texture into another render texture my guess would be any issue is relevant only when reading out FBO textures.

The fix makes sense to me, but I’m not yet sure why the issue was there in the first place.

2 Likes