blending

This is a discussion on blending within the Game Programming forums, part of the General Programming Boards category; Can anyone explain blending to me better than the OpenGl Programming Guide can. I know to make something transparent, you ...

  1. #1
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926

    blending

    Can anyone explain blending to me better than the OpenGl Programming Guide can. I know to make something transparent, you use
    Code:
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    But I don't understand why that works and I don't understand what all the other Macros do here are all of them
    Code:
    GL_ZERO  source or destination  (0, 0, 0, 0)
    GL_ONE  source or destination  (1, 1, 1, 1)
    GL_DST_COLOR  source (Rd, Gd, Bd, Ad)
    GL_SRC_COLOR destination  (Rs, Gs, Bs, As)
    GL_ONE_MINUS_DST_COLOR source (1, 1, 1, 1)-(Rd, Gd, Bd, Ad)
    GL_ONE_MINUS_SRC_COLOR   destination (1, 1, 1, 1)-(Rs, Gs, Bs, As)
    GL_SRC_ALPHA  source or destination (As, As, As, As)
    GL_ONE_MINUS_SRC_ALPHA  source or destination  (1, 1, 1, 1)-(As, As, As, As)
    GL_DST_ALPHA  source or destination  (Ad, Ad, Ad, Ad)
    GL_ONE_MINUS_DST_ALPHA  source or destination  (1, 1, 1, 1)-(Ad, Ad, Ad, Ad)
    GL_SRC_ALPHA_SATURATE source (f, f, f, 1); f=min(As, 1-Ad)

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    You're specifying how you want everything to be blended.

    glBlendFunc(source factor, destination factor)

    The source color will be whatever you last specified with glColor, or the current texture that you're working with. The destination is what is already sitting in memory in the color buffer. So glBlendFunc will take the factors of those two to figure out what new color should be there

    final color = source factor * source color + destination factor * destination color

    Looking back at the line you wrote, glBlendFunc is telling OpenGL to scale your source by the alpha channel you specified. The destination will be scaled by one minus the alpha channel of the source.

    So if the source had an alpha of 1.0, which would be full alpha, the source would be scaled by 1 and the destination would be scaled by 0, making the source color completely overide the destination. If the alpha were 0.5, the source colors would be halved, and the destination would be scaled by 1 - 0.5, which comes out to half as well, giving you a 50/50 blend.

    The other macros will cause different calculations to be made. but they will all follow the basic formula I have above. I hope that clears things up.

  3. #3
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    Thank you. I have posted in on more than 3 forums and you are the only one to respond. I understand now and greatly appreciate it.
    reputation.skorman00++

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    you may find this link of use,

    this link of use

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    There was a discussion about blending and the formulas for several types on the GD board about 2 weeks ago.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cant compile OpenGL blending
    By KIBO in forum Game Programming
    Replies: 3
    Last Post: 06-17-2008, 07:58 AM
  2. Blending Problem
    By IdioticCreation in forum Game Programming
    Replies: 1
    Last Post: 02-16-2008, 05:13 PM
  3. Blending troubles
    By SniperSAS in forum Game Programming
    Replies: 4
    Last Post: 06-02-2006, 08:34 PM
  4. Alpha blending w/o color loss
    By VirtualAce in forum Game Programming
    Replies: 37
    Last Post: 10-27-2004, 12:58 AM
  5. Alpha blending
    By SMurf in forum Game Programming
    Replies: 3
    Last Post: 08-29-2003, 06:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21