Results 1 to 3 of 3

Thread: 2d Shadows

  1. #1
    Junior Member Newbie
    Join Date
    May 2007
    Posts
    1

    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/p...ardShadows.gif

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

    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/art...rticle2032.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?

  2. #2
    Junior Member Newbie
    Join Date
    May 2007
    Location
    Argentina
    Posts
    1

    Re: 2d Shadows

    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?

  3. #3
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,107

    Re: 2d Shadows

    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.

Similar Threads

  1. Deferred Shadows or Forward Shadows?
    By mrMatrix in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 01-18-2016, 01:01 PM
  2. Problem with point light shadows (cubemap shadows)
    By Ryno Engine in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 08-20-2015, 04:36 AM
  3. using shadows
    By Pswin in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 01-25-2008, 11:29 PM
  4. help with shadows
    By ricfow in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-18-2004, 06:17 AM
  5. Replies: 2
    Last Post: 08-17-2003, 01:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean