Rendering shadow sprites in cocos2d-x
- by lukeluke
I am writing a 2D game with cocos2d-x. I want to put a "shadow" sprite on a background sprite using the equation:
MAX(0, Cd*1 - Cs*S)
where Cd is the destination color (that is, a background pixel), Cs is the source color (the shadow pixel) , S is the scale factor (between 0 and 1).
The MAX() function is used to avoid negative results. This is a lighting effect: when the shadow sprite pixel is 0, there is no effect on the background
pixel, otherwise, the background pixel becomes darker.
Now, the only way that comes to my mind is to change the blending equation to GL_FUNC_SUBTRACT, but it doesn't compile with cocos2d-x (can't found it)...
I would subclass the CCSprite class in order to implement the draw() method in order to change, when needed, the blending equation, call the original draw() method and restore the blending equation to its previous state at the end of the method.
So my questions are two:
how to use glBlendEquation() with cocos2d-x? Keep in mind that i am writing a game for iphone/android/windows.
are shadows handled this way in 2D games?
Thx