OpenGL Shadow Color
Myrdos

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

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

Trent Gamblin

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

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

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

Yeah, that makes sense.

Even better! Cookies all around!

gnolam

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

Trent Gamblin

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

Thread #605236. Printed from Allegro.cc