Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm currently trying to implement a type of "smooth" lighting. How can I achieve lighting which looks like this:

http://dl.dropbox.com/u/1668516/concept/warp3.png

Using OpenGl. I've attempted to use blending modes and have come very close to making it work but it came out like this: https://pbs.twimg.com/media/A1071viCEAAlFmJ.png

Edit: The technique usedis drawing the lighting image (a white gradient) then drawing all my images using the blending effect glBlendFunc(GL_DIST_COLOR,GL_ZERO) however the images come out slightly transparent as shown previously I also have no control of how dark the black background is.

and I also wasn't able to change the alpha of the black background which I want to be able to do.

Could I get a few pointers in the right direction?

share|improve this question
1  
From the screenshots it's hard to understand what your problem is. Could you describe more what is wrong with your own result and what would you like to achieve? –  msell Oct 21 '12 at 6:00
    
Could you post what tutorial you are following or how you do it? –  Miro Oct 21 '12 at 9:20
add comment

1 Answer

up vote 1 down vote accepted

The problem with using glBlendFunc(GL_DIST_COLOR,GL_ZERO) multiple times is that you'll only be able to take away light, not add more light to the scene - which will be a problem as soon as two or more light overlap. You can fix this problem by rendering all the lights additively to an offscreen buffer and then drawing the whole thing at once after finishing the rest of the scene.

To create and maintain an offscreen buffer, you can use an OpenGL Framebuffer Object as described here: http://www.opengl.org/wiki/Framebuffer_Object. You can essentially draw on it the same way you can draw to the backbuffer / screen. For accumulating all the lights there, you can use a simple additive blending mode:

glBlendFunc(GL_SRC_ALPHA, GL_ONE)

which will also allow you to use the alpha channel of the light.

share|improve this answer
    
What would you use to draw? A white circle texture? –  PsychoDad May 29 '13 at 19:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.