r/gamedev•
RussianT34

[OpenGL] Can't get 2d lighting working

So, I'm working on a little sh'mup where the player is a tank and drives around various levels eliminating enemies. I'm trying to make it so the level is very dark and the tank must rely on a light to navigate. Since it's 2D, I can't use OpenGL's lighting system, so I'm relying on alpha-blending to achieve what I need.
Essentially, I am rendering the map, player, etc. Then I fill the screen with black at an alpha of 80%, then render a white "light" texture.

Code here: https://gist.github.com/2980982
Update() code here: https://gist.github.com/2980990
The result is this: http://i.imgur.com/D6sOA.png (the "light" is the square)

But I'm looking for some way to make the light "brighter." Am I going about this the right way? And how can I achieve what I want?

EDIT: Okay, so after much more experimentation with blending functions, changing line 20 from glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA) to glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR) gives me a much "brighter" light, but now it takes up the entire primitive, rather than the circular one I had originally.

Posted Jun 24, 2012, 1:54 AM UTC · edited

17
Loading comments…