Reputation: 354
Is it possible make a CCSprite to black and white one using setBlendFunc ? If yes please tell how to do it.
More Details:
I have to make my game sprite (background,character) to gray salce/black and white for a certain point of time. I dont want to take another image for this. I have tried CCTexture2DMutable. But the thing is it take extra memory of the same sprite.
Is there any way to use one mask image and make all sprite to gray scale. Please help.
Upvotes: 3
Views: 2497
Reputation: 6942
This is not mathematically correct grayscaling, but looks black & white:
// setup grayscaling:
GLfloat rgba[4] = { 0.65f, 0.65f, 0.65f, 1.0f };
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB );
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, rgba );
glTexEnvi( GL_TEXTURE_ENV, GL_SRC0_RGB, GL_CONSTANT );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR );
glTexEnvi( GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR );
// ... glDrawArrays() here ...
// turn off grayscaling:
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
Insert this code into CCSprite drawing method. 0.65f
value of rgba
is set experimentally, try to tune it.
Upvotes: 2
Reputation: 289
It is not possible to do so via setBlendFunc however it can be done using CCMutableTexture. If this a viable alternative, I will post the required code to do so.
Upvotes: 1