SDL light effects

Started by
6 comments, last by marsong 11 years, 9 months ago
So I want to make a game that uses light. I want the player to be able to be in a dark room and carry a light so the area around him lights up. I am not exactly sure how to go about doing this so if someone could explain the best way to go about doing this or point me in the direction of a tutorial that would be nice.
Advertisement
OpenGL Is compatible with SDL and is going to be your best bet. It's not super friendly at first but slowly it will grow on you. Most people think that OpenGL is only used in 3d games, but it is also a viable choice for 2d games (which I assume you are making). OpenGL will also allow you to do more things than just blit to the surface like SDL does. If your wanting lighting you will probably want to look into doing OpenGL lighting.

You will need to learn OpenGL though in order to use this effectively, but once you learn it you won't have to learn a new library for 3d (although you may need to learn a few more OpenGL concepts).

Here's a link to the book I have on OpenGL and so far I have found it pretty useful: http://www.amazon.co...2707587&sr=1-29

Here's a link to a tutorial in doing lighting in OpenGL (although I think it's 3d): http://www.sjbaker.o...l_lighting.html

Fly Safe 7o

No need to use OpenGL - though it will certainly open up lots more possibilities. Alpha blending will do what you need in plain SDL.

Assuming your art assets were created looking like they are lit up, at runtime you actually want to darken everything that's not under the light.

I suggest experimenting with blended layers in a paint program until you get the effect you want (hint - additive or multiplicative), then work out how to set up blending in SDL to reproduce your chosen effect.
[size="1"]

No need to use OpenGL - though it will certainly open up lots more possibilities. Alpha blending will do what you need in plain SDL.

Assuming your art assets were created looking like they are lit up, at runtime you actually want to darken everything that's not under the light.

I suggest experimenting with blended layers in a paint program until you get the effect you want (hint - additive or multiplicative), then work out how to set up blending in SDL to reproduce your chosen effect.


If you are going to use Alpha Blending in SDL you really, really, really should use the development version (2.0) since it is fairly slow in 1.2.
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
I think it could be relatively simple. If the camera follows your character in a fixed center point you could overlay the rendering with an image that has a transparent center point which fades into black around the edges. You could even make this a sprite and animate it slightly for a closer feel of having a torch lighting the zone.

Then I suppose you could calculate the distance of your character and other objects to provide the illusion that they are essentially appearing within the viewport area.

[size=1]I "surf" the web, literally.

if you want to make game, just use some game editor like UDK.

I think it could be relatively simple. If the camera follows your character in a fixed center point you could overlay the rendering with an image that has a transparent center point which fades into black around the edges. You could even make this a sprite and animate it slightly for a closer feel of having a torch lighting the zone.

Then I suppose you could calculate the distance of your character and other objects to provide the illusion that they are essentially appearing within the viewport area.


Yea I was thinking of doing this but if I wanted more then one torch I would have trouble

Yea I was thinking of doing this but if I wanted more then one torch I would have trouble


You could implent a basic lightmap:

Setup an array as big as your screen:
uint8_t lightmap[SCREEN_SIZE];

- Reset lightmap to 0 (black)
- Do one pass and fill this lightmap, you would basically take your lightsources, fill in whites in your lightmap at their position (use some fade out formula so it gets darker further away from the light source)
- Alpha blend (multiplicative blend) the screen with your lightmap

Although, doing this in software is gonna be pretty slow if you use a high resolution.

This topic is closed to new replies.

Advertisement