Dark Bit Factory & Gravity

PROGRAMMING => General coding questions => Topic started by: Stonemonkey on December 07, 2006

Title: opengl blending
Post by: Stonemonkey on December 07, 2006
I'm trying to do something with blending but can't get it working. I'm wanting to take a texture and blend it with a colour from the pixel buffer :

texture_colour*dst_colour + dst_alpha*dst_colour

and have:

GlEnable(Gl_Blend)
glBlendFunc(GL_Dst_Color,GL_Dst_Alpha)

the 'texture_colour*dst_colour' works fine but the ' dst_alpha*dst_colour' part seems to add 'dst_alpha*white'

Anyone got any ideas what I'm doing wrong?
Title: Re: opengl blending
Post by: ninogenio on December 07, 2006
hmm im not really sure what you mean i usually do this for my blending.

glColor4f 1.0, 1.0, 1.0, 0.4
glEnable GL_BLEND
glBlendFunc GL_SRC_ALPHA, GL_ONE
Title: Re: opengl blending
Post by: Stonemonkey on December 07, 2006
ty ninogenio, it's for my lighting rather than alpha blending though and i've got it working now. Was something I was doing with multitexturing in an earlier stage.
Title: Re: opengl blending
Post by: Jim on December 07, 2006
Nino, you should probably use
glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
otherwise you'll end up with a bit of a glow effect - or perhaps that's what you wanted in the first place?
ie. right now you have (0.4 in the alpha colour)
pixel = 0.4 * src + 1.0 * dst.
which is src and dst are both white would give you 1.4 * white (ie. overbright, so some colours near-white will end up white).
In the version I posted you have
pixel = 0.4 * src + (1.0-0.4) * dst.
which has a maximum of 1.0.

Jim
Title: Re: opengl blending
Post by: ninogenio on December 07, 2006
ahh right what am i thinking your right jim.

cheers for the pointer btw ;)