kutschenator
kutschenator

Reputation: 922

CCRenderTexture and CCDirector render differently?

i wanted to use CCRenderTexture in my project because i have a lot of CCLabelBMFont that are mostly static. Adding them all to my Scene caused some performance issues (Yes you can use BatchNotes etc. but it didnt really help). So I rendered them into a single Texture which increased the performance significantly! But the problem is that the rendered texture and the directly rendered node look different. I have no idea why!

I created a cocos2d-sample project and and created this:

CCSprite* testImage = [CCSprite spriteWithFile:@"N.png"];
testImage.position = ccp(100,100);
CCRenderTexture *rt = [CCRenderTexture renderTextureWithWidth:786 height:1024];
[rt beginWithClear:0 g:0 b:0 a:0];
[testImage visit];
[rt end];
CCSprite* renderedSprite = [CCSprite spriteWithTexture:rt.sprite.texture];
renderedSprite.position = ccp(386,512);
// Flip because CCRenderTexture is flipped
renderedSprite.flipY = YES;
// Add normal node an the rendered sprite
testImage.position = ccp(130,100);
[self addChild:testImage];
[self addChild:renderedSprite];

The results look like this: The texture has less glow

How can this be? How can i make them look the same? The N on the right is the sprite added the "normal" way and it is displayed correctly. The N on the left is the texture.

Edit: i found this tutorial which hints that the blend functions are different. so can i am looking for the correct function to make them look the same.

Upvotes: 1

Views: 789

Answers (1)

kutschenator
kutschenator

Reputation: 922

I found the solution! I used this example to create the sprite but when i looked into the cocos2d-manual again i saw, that you can add the CCRenderTexture directly to your scene. Thats what i did and it solved the problem!

So the correct code should be:

CCSprite* testImage = [CCSprite spriteWithFile:@"N.png"];
testImage.position = ccp(100,100);
CCRenderTexture *rt = [CCRenderTexture renderTextureWithWidth:786 height:1024];
[rt begin];
[testImage visit];
[rt end];
rt.position = ccp(386,512);
// Add normal node an the rendered sprite
testImage.position = ccp(130,100);
[self addChild:testImage];
[self addChild:rt];

Upvotes: 3

Related Questions