PDA

View Full Version : Need advices with 2D lighting



Brunooo
08-12-2009, 10:35 AM
Hello!

One of the greatest effects in games is the lighting effect. That makes the game much more real.
I would like to make a lighting effect on a 2D game that uses OpenGL (+ SDL), a very basic lighting effect. All my drawing is based on textures (2D images).
I had many ideas, and I tought that it would be easy, just doing some blending... But I realised that blending is not that fast!
Trying to make a dark scenario (night with no lights), I drawed a dark transparent rect, but it droped from 360 fps to 250 here, and from 90 to 45 on another old PC!
So I searched a little and found that 'glColor' is very helpfull and I made that scenario (the night) without loosing 1 single FPS! I just used 'glColor3f(0.2,0.2,0.2)'!
Then I could make some logic in the vertexes to make a lighting effect!

I would like to know if someone done some lighitng effect in a 2D game using OpenGL. What do you recommend?
If I would use glColor to make the lighting I would have to split the textures in blocks right? For example the maximum size of the texture block would be 12x9, to make the vertex lighting very accurate!
What do you suggest?

Thank you!

MarkS
08-12-2009, 01:42 PM
Nothing in OpenGL is truly 2D. You are texturing a bitmap onto a 3D polygon with the z values set at 0 or 1 or something. Even if you use glVertex2f(), the z value is still set, but set internally. Turn on lighting and set the lights around the world in 3D space.