Question

Here is what my code look like

CCSprite *sp = [CCSprite spriteWithFile:@"textureWithOneColorbackground.jpg"];

[self addChild:sp];

// Change the blending factors
[sp setBlendFunc:(ccBlendFunc){GL_ONE, GL_ONE}];
[sp setColor:ccBLACK];

The original texture color is (246,149,32) The outcome now is (0, 0, 0)

According to OpenGL, the calculation should be like this: ((246 * 1 + 0 * 1), (149 * 1 + 0 * 1), (32 * 1 + 0 * 1)) So it should be the same.

Don't know why I am doing wrong here, can someone help me out?

Regards,

Was it helpful?

Solution

[sp setBlendFunc:(ccBlendFunc){GL_ONE, GL_ONE}];

setBlendFunc sets glBlendFunc. source blending factor and destination blending factor.

[sp setColor:ccBLACK];

setColor doesn't mean it is for destination blending color. It means to set color for vertex color.

You set black (R=0,G=0,B=0,A=1) for vertex color and if background color is black,

(([texture color]246 * [vertex color](0 / 255) * [GL_ONE]1 + [background color]0 * [GL_ONE]1), (149 * (0 / 255) * 1 + 0 * 1), (32 * (0 / 255) * 1 + 0 * 1)) = (0, 0, 0)

iPhone 3D Programming is a nice book for understanding OpenGL ES on iPhone.

OTHER TIPS

According to the docs:

http://www.cocos2d-iphone.org/api-ref/0.99.0/interface_c_c_sprite.html#af0c786f0f5b4081a4524e78eda9c8734

The Blending function property belongs to CCSpriteSheet, so you can't individually set the blending function property.

You seem to be applying it to the sprite and not the sheet. Try applying the blend to the sheet.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top