Alpha blended light map using OpenGL

Hmmm … I hope this isn’t too off topic kicks self if is.

I’m using SDL to access Open GL or standard SDL (depending on flag) a little
like gSDL, I guess (although I haven’t used this, and only assume).

Anyway, my GL experience is extremely limited, but what I want to do is take
advantage of the yummy free alphablending to create nice light maps without
touching GL’s lighting. The reason I don’t need the GL lighting is all I
have is a 2D world displayed using orthogonal mode in GL. So essentially
everything is pure 2D, just nice and fast.

I want to somehow apply alphablended light definition images (black images
with greater and greater transparancy towards the centre so that it acts
like a nice spot light if everything around it is black) on a black area the
size of the screen. merge the alpha blended areas with the black area, and
then paste the image over the top of my tiled display every iteration.

Now of course I can display a black image that has predesigned alpha levels,
but I want dynamic lights that move around, so I need to be able to have a
solid black image the size of the screen which I merge the alpha level light
images with to created a black area with alpha levels (the lights) which is
then applied to the screen.

Phew.

Is it simple?
Am I simple?

Anyway, any help, even if it be that I’m an idiot that doesn’t know what
they’re talking about, would be much obliged, thanks guys,

Rob_________________________________________________________________
MSN Instant Messenger now available on Australian mobile phones.?Go to
http://ninemsn.com.au/mobilecentral/hotmail_messenger.asp

[…alpha for lightmaps…]

Well, you could do it that way in some special cases, but you can’t
separate the alpha channel, only modulate it… And alpha blending
isn’t exactly free with h/w acceleration - it’s just much cheaper
in relation to plain rendering than it is in software implementation.

Normally, lighting and light effects are implemented using two other
forms of blending: Multiplicative and additive blending.

For lightmaps, instead of alpha blending a black…transparent image
over stuff, multiply with a black…white image. In fact, the
lightmaps can be colored. There’s no need for alpha channel. Black
means black, white means “no effect” and 50% gray means “50%
intensity”.

Additive blending is generally used for highlights, lens flares and
that kind of stuff. This also works with colored lighting textures.
No alpha channels. Black means “no effect”, white means white
(saturation), and 50% gray means “add 50% light, saturating at
white”.

//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Thursday 27 February 2003 03.06, Robert Sadedin wrote:

Really (apologies, no disbelief intended, rather delighted interest)?
How does one go about applying the multiplactive or additive blending using
OpenGL?

Thanks David.> ----- Original Message -----

From: david@olofson.net (David Olofson)
To:
Sent: Thursday, February 27, 2003 8:20 PM
Subject: Re: [SDL] Alpha blended light map using OpenGL

On Thursday 27 February 2003 03.06, Robert Sadedin wrote:
[…alpha for lightmaps…]

Well, you could do it that way in some special cases, but you can’t
separate the alpha channel, only modulate it… And alpha blending
isn’t exactly free with h/w acceleration - it’s just much cheaper
in relation to plain rendering than it is in software implementation.

Normally, lighting and light effects are implemented using two other
forms of blending: Multiplicative and additive blending.

For lightmaps, instead of alpha blending a black…transparent image
over stuff, multiply with a black…white image. In fact, the
lightmaps can be colored. There’s no need for alpha channel. Black
means black, white means “no effect” and 50% gray means “50%
intensity”.

Additive blending is generally used for highlights, lens flares and
that kind of stuff. This also works with colored lighting textures.
No alpha channels. Black means “no effect”, white means white
(saturation), and 50% gray means “add 50% light, saturating at
white”.

//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Check out glBlendFunc(). It takes two arguments; one for the source
and one for the destination. Each is an enum, with values such as
GL_ONE, GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA. For example

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

gives you traditional alpha blending, while

glBlendFunc(GL_ONE, GL_ONE);

results in additive blending. For multiplicative blending, you’ll have
to use multitexturing, as OpenGL (at least 1.1, AFAIK) doesn’t
support multiplicative blending through glBlendFunc(). You could use
subtractive blending for lightmaps, but it doesn’t produce the exact
same effect, obviously.

Anyway, this doesn’t have much to do with SDL. You’re probably better
off looking for OpenGL specific docs, tutorials or forums.

//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Thursday 27 February 2003 12.47, Robert Sadedin wrote:

Really (apologies, no disbelief intended, rather delighted
interest)? How does one go about applying the multiplactive or
additive blending using OpenGL?