2d Light effect with SDL
i would like to create a light effect on a 2d car racing written in SDL.NET (and 开发者_开发知识库c#). The psychs Light effect is simple: the car headlights (classic conic light effect). Does somebody know where can i look for some example of light managemnt via SDL ? Or maybe tell me how to solve this issue ? Thank you for your support !
Update: actually i've created an image with gimp with a simulation of light. Then i load it in front of my car sprite to simulate the light. But i don't like this type of approach... maybe is more efficient than a run-time generation/simulation of a light!
If you're looking at pure 2D solutions, you just want to attach the headlights sprite to your car sprite. There is no "light management" here. Just an alpha-blended sprite.
To improve the effect, you might want to create and use two sprites actually:
- one small, directed for the conic headlight effect
- one much bigger, haloish, to increase lighting in front of the car on a large area.
Note: you might do the second without images, if you can create an alpha-blended primitive in SDL of the proper shape.
If you need a realistic lighting model you have to change to opengl or directx and use a shader like deferred lighting. This is an example for xna.
How about using multiple images instead?
Since SDL doesn't have shader effects, I would suggest breaking the conical image into small parts depending on the detail you want, and collision checking with the objects in front of the image and drawing only the parts required.
It's a hack, but it can look good if you divide the "glow" images both vertically and horizontally.
精彩评论