# How can I achieve this lighting with OpenGL?

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?

• 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? – kravemir Oct 21 '12 at 9:20
• This question seems to be utterly of no use anymore due to the fact that one of the linked images is not available anymore. – dot_Sp0T May 30 '17 at 5:31

## 1 Answer

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.

• What would you use to draw? A white circle texture? – jjxtra May 29 '13 at 19:40