- Online Community Forums » Programming Questions » The workings of glBlendFunc

Credits go to gillius, James Howard, and Krzysztof Kluczek for helping out!
This thread is locked; no one can reply to it. rss feed Print
The workings of glBlendFunc
Rob Fletcher
Member #2,830
October 2002


I'm a little confused, and I'm having trouble googling my troubles away. I'm getting into some of OpenGLs blendy abilities, so glBlendFunc has become of interest to me.

There is no shortage of the manual out there, but I don't quite get something.

I think what I'm not understanding is what color scaling is all about. At least, why there would be two of them. In my brain, I see blending as having a function that takes the new and the old colors, does stuff to them, returns the output color. Functions are like 'add', 'screen', etc... Yet, glBlendFunc asks for two parameters, and I can't seem to understand it.

Could somebody please explain to me (or maybe link to something with a good explanation) glBlendFunc's two parameters and how they affect the blending?



James Howard
Member #262
April 2000

sfactor is the source colour
dfactor is the destination colour

manual said:

Specifies how the red, green, blue and alpha source blending factors are computed

Specifies how the red, green, blue and alpha destination blending factors are computed

e.g. if you call glBlendFunc(GL_ONE, GL_ONE), and
source colour = r:0.2, g:0.4, b:0.1
dest colour = r:0.1, g:0.1, b:0.6
output colour = r:0.3, g:0.5, b:0.7

Check out my final year university project 'Warring States', a 3-D multiplayer RTS game:

Member #119
April 2000

I believe it does "s * s_fac + d * d_fac", where you give it s_fac and d_fac. In the previous post, GL_ONE was used, so it became s+d, or an additive blend.

Gillius's Programming --

Krzysztof Kluczek
Member #4,191
January 2004

Yes, OpenGL blending takes source and destination colors, multiplies them by something and then adds them. glBlendFunc specifies what those colors should be multiplied by.

Possible modes:

  • GL_ZERO - color is ignored

  • GL_ONE - full color is taken into addition

  • GL_###_COLOR - color is multiplied by ### color

  • GL_ONE_MINUS_###_COLOR - color is multiplied by inverted ### color

  • GL_###_ALPHA - color is multiplied by ### alpha value

  • GL_ONE_MINUS_###_ALPHA - color is multiplied by inverted ### alpha value

  • GL_SRC_ALPHA_SATURATE - color is multiplied by MIN(src_alpha,1-dst_alpha) (may not work in some implementations)

where ### can be:
SRC - source
DST - destination

Note that OpenGL some combinations may not work, like multiplying color by itself.

glBlendFunc(GL_ONE,GL_ZERO); - everything works as usual, despite blending turned on
glBlendFunc(GL_ZERO,GL_ONE); - nothing is being drawn (Z-buffer may be still affected)
glBlendFunc(GL_ONE,GL_ONE); - colors are added (values >1 are clipped to 1)
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - transparency: alpha=0 - invisible, alpha=1 - no transparency

Rob Fletcher
Member #2,830
October 2002


It all clicks now. Thanks guys. Sometimes when my brain isn't in math-mode I forget the implications of the term "factor".

It makes good sense now, thanks!


Free Market Evangelist
September 2000


Note that OpenGL some combinations may not work, like multiplying color by itself.

Unless NV_blend_square is supported, of course ;D

- Bob
[ -- All my signature links are 404 -- ]

Go to: