2d Shadows

For a school project we are trying to get shadows + lighting to work in a 2d game.

I created a method with pixel blitting (SDL) but it doesnt use a GPU so it is slow.

What it does:
render the scene>
create a full screen overlay with RGB(0,0,0)
for each light: add alpha value to overlay
blend overlay ALPHA with scene

this gives me shadows like:
http://images.gamedev.net/features/programming/2dsoftshadow/04HardShadows.gif

problem: it is pretty slow (8ms to create lightmap + render @ 1024*768)

Now i’m trying to do this with OPENGL but i can’t get it to work.

What i’m trying to do at the moment:
fill screen with black, alpha at 0.
disable color buffer
render lights to alpha channel
render scene, blending with the current alpha values

actually someone made a tutorial for this doing exactly what i’m doing without opengl but i can’t get some things to work:
http://www.gamedev.net/reference/articles/article2032.asp

filling the screen with black and resetting the alpha channel works
filling the alpha channel with the lights: doesnt work, what should i use as parameters for glblendfunc ?
rendering the scene: haven’t tried it

I guess there are more people that have done shadowing like this or maybe some people who know of a better method.

Someone knows what i’m doing wrong?

hi…

were you able to fix that? i seem to have the same problem and havent the slightest idea how to fix it. could u give me a hand?

filling the alpha channel with the lights: doesnt work

  1. Clear alpha channel to 0
  2. Only fill alpha channel for one light - don’t blend, just replace.
  3. Now render everything affected by this light using glBlendFunc(GL_DST_ALPHA, GL_ONE).
    It means what you draw is scaled by alpha channel stored in the framebuffer and added to what you have in color buffer.

Repeat all steps for all ights. You can’t do all lights at once.