Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » OpenGL Shadow Color

Credits go to gnolam and Trent Gamblin for helping out!
This thread is locked; no one can reply to it. rss feed Print
OpenGL Shadow Color
Myrdos
Member #1,772
December 2001

I've finally got projection shadows working in OpenGL, however the only way I know to draw them is in solid black:

#SelectExpand
1 glDisable(GL_BLEND); 2 glDisable(GL_LIGHTING); 3 glColor4f(0.0, 0.0, 0.0, 0.0); 4 glPolygonMode(GL_FRONT_AND_BACK, polygonMode);

Does anyone know how to draw transparent shadows? I basically want to blend the existing color with the color black, but everything I've tried results in no shadow at all!

__________________________________________________

gnolam
Member #2,030
March 2002
avatar

So what happens if you enable blending (with an appropriate glBlendFunc()) and use a > 0 alpha value?

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Trent Gamblin
Member #261
April 2000
avatar

As a start, and maybe push in the right direction, you'll need GL_BLEND on, and set glBlendFunc to something like "glBlendFunc(GL_ALPHA, GL_INVERSE_ALPHA)".

Myrdos
Member #1,772
December 2001

Hmm, I don't fully understand these blending functions... I fooled around until I found a combination that seems to work:

#SelectExpand
1 glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2 glDisable(GL_LIGHTING); 3 glColor4f(0.0, 0.0, 0.0, 0.5); 4 glPolygonMode(GL_FRONT_AND_BACK, polygonMode);

And the produced shadow (from the red cube):
{"name":"shadow_blended.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/7\/476bc4b4b0c009fee76011d5179a3662.png","w":788,"h":505,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/7\/476bc4b4b0c009fee76011d5179a3662"}shadow_blended.png

__________________________________________________

Trent Gamblin
Member #261
April 2000
avatar

Yeah, that makes sense. ONE_MINUS_ALPHA is what I meant, but I'm used to Allegro 5 terms which call it INVERSE_ALPHA.

Myrdos
Member #1,772
December 2001

Yeah, that makes sense.

Even better! Cookies all around!

__________________________________________________

gnolam
Member #2,030
March 2002
avatar

Normally, you'd want glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). That's the "standard" translucency blending function.

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Trent Gamblin
Member #261
April 2000
avatar

Oops, what gnolam said. I didn't catch that. :x

Go to: