Sign in to follow this  
deathwearer

SDL+OpenGL - Lighting and other effect

Recommended Posts

Alright, I'm building a RPG game with SDL, so yes it's in 2D ( Gonna be a FF-like ) For now everything is going fine, but i was wondering, is it possible to add some lighting effect in my game? And some other effect like a FOG at some area? Because such effect would add a nice atmosphere in my game ^^ Thank. And if you can refer me to a tutorial or info, please do so.

Share this post


Link to post
Share on other sites
Yes, it should be quite easy. If you render simple quads for your sprites, you can set the colour to be something other than white, to simulate coloured lighting. For fog, you could take a grey cloud texture and alpha blend it over the top of everything (for example), by setting the alpha values to less than 1.0. It's quite straightforward, assuming you're already ok with using OpenGL for 2D.

Share this post


Link to post
Share on other sites
1. I'm not sure i really understand what you are saying for the lighting effect.

2. Thank, that will fit i guess, can i make these fog animated also? ( i guess yes )

And no i don't have any experience with OpenGL, ( some with DX ) but i will try to learn it anyway to make the fog. This is not going to prevent me for making that game ;)

Thank for your help.

Share this post


Link to post
Share on other sites
What Kylotan was saying about lighting was that it can easily be simulated by just changing the colour of the sprite, e.g. by using glColor3f.

Though if you're not familiar with OpenGL at all, it might be hard to understand just what Kylotan was explaining. I suggest that you take a look at NeHe, where you will find some good tutorials on OpenGL.

Share this post


Link to post
Share on other sites
Alright, Thank guys, that's gonna help a lot.

Last question, for the lighting, using what your saying, that will change the color to be a bit brighter?

And yes, that's seems hard to understand, but like i said nothing is gonna prevent me for making that game, it's already going very well, and not gonna fail ;)

Share this post


Link to post
Share on other sites
No, it's not going to make it any brighter than the texture/sprite already is. glColor3f(1.0, 1.0, 1.0), which is the default, is the brightest it gets.

Usually, in a 2D game like this, the "lighting" is actually baked into the sprite itself. So that it's usually hand-drawn. Any sort of dynamic lighting for a 2D game like that can be very difficult.

With that spirit, I'm sure you'll do great. Keep up the good work!

Share this post


Link to post
Share on other sites
So if making those lighting effect would be hard like you say in such a game, how about the opposite? Making "dark" area instead. Maybe the same way i make a fog, but the sprites would be black, non-animated. And just with a bit of setting it would apear Like there is lighting effect? ^^

Share this post


Link to post
Share on other sites
Quote:
Original post by James Trotter
No, it's not going to make it any brighter than the texture/sprite already is. glColor3f(1.0, 1.0, 1.0), which is the default, is the brightest it gets.


What makes you think that glColor3f(2.0, 2.0, 2.0) is not possible?

Just because it's 100% doesn't mean that 1.0 is the brightest.

Note that I haven't tried it, but I can't see any reason why it wouldn't work.

From the documentation of glColor :

Neither floating-point nor signed integer values are clamped to the
range [0,1] before the current color is updated. However, color compo-
nents are clamped to this range before they are interpolated or written
into a color buffer.


Mark

Share this post


Link to post
Share on other sites
Quote:
However, color compo-
nents are clamped to this range before they are interpolated or written
into a color buffer.


This is the important part to note, correct me if I'm wrong, but as far as I know, the color buffer is the final stuff you see, so if its clamped to 1.0 before being written to the color buffer, then 1.0 is full intensity.

What your thinking of is High dynamic range which is what is used to create bloom effects. In effect you could cast a really bright light on the tiles, and they would appear to glow. However glColor3f(2.0,2.0,2.0); will look the same as glColor3f(1.0,1.0,1.0);.

Again, I could be wrong, and I apologize in advance if I am.

Share this post


Link to post
Share on other sites
Yeah,

[all to the last posts]
Methinks BleedingBlue is correct. There's really no point in using 2.0f explicitly in your lighting stuff, as it will be dealt with as if it were 1.0f. That is, the triangles will be drawn in the same manner as 1.0f. Who knows, maybe eventually there'll be an extension which allows values larger than 1.0f to be clamped at rasterisation, but I don't currently know of any.

Oh, and dynamic lighting is always fun in 2D :D.

--CJM

Share this post


Link to post
Share on other sites
What I am doing, and this is still pretty new to me as well, is sort of what Kylotan was implying about light. I apply a light setting to each vertex of the tilemap. Most times it is ignored because they are all full on but anyway. This consists of an array of bytes which represent the alpha value to apply to the light color. By rendering a colored quad using the byte array for vertex alpha value over each tile after your initial rendering is done, you can get some pretty neat effects. I have done this to some grass fields to give it the effect of some height variances and by randomizing the byte values inside a radius I get some pretty cool flicker effects for torches etc.

I have been able to render ~3000 32x32 quads with blending enabled to a 640x480 screen at 16bpp at ~300 fps consistently on a 1.7Ghz e-machine with 512mb RAM and a GForce FX 5200 PCI 128mb. This is not a high end machine and trust me the code isn't very optimized, each quad has a glBegin/glEnd call. And there is also some text rendered to the screen as well to show the FPS. I doubt the lighting effect I used above (if used wisely) will effect a games performance too much.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this