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)
Cd is the destination color (that is, a background pixel),
Cs is the source color (the shadow pixel), and
S is the scale factor (between 0 and 1).
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?