Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


SDL light effects


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 PhantomRonin   Members   -  Reputation: 131

Like
0Likes
Like

Posted 18 July 2012 - 09:05 PM

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.

Sponsor:

#2 DeafTV   Members   -  Reputation: 1236

Like
0Likes
Like

Posted 19 July 2012 - 08:24 AM

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


#3 mrbastard   Members   -  Reputation: 1573

Like
0Likes
Like

Posted 19 July 2012 - 11:43 AM

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.

Edited by mrbastard, 19 July 2012 - 11:44 AM.



#4 SimonForsman   Crossbones+   -  Reputation: 6293

Like
2Likes
Like

Posted 19 July 2012 - 01:50 PM

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.
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!

#5 DZee   Members   -  Reputation: 190

Like
0Likes
Like

Posted 19 July 2012 - 06:43 PM

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.

I "surf" the web, literally.


#6 xueweuchen   Members   -  Reputation: 97

Like
0Likes
Like

Posted 20 July 2012 - 09:21 AM

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

#7 PhantomRonin   Members   -  Reputation: 131

Like
0Likes
Like

Posted 20 July 2012 - 12:31 PM

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

#8 marsong   Members   -  Reputation: 154

Like
0Likes
Like

Posted 20 July 2012 - 11:33 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS