Results 1 to 7 of 7

Thread: glBlendFunc with transparent drawables

  1. #1
    Member Newbie
    Join Date
    Nov 2003
    Location
    NSW
    Posts
    33

    glBlendFunc with transparent drawables

    Hi there,

    I've got a non-intuitive thing going on with glBlendFunc and a transparent drawable. Here's what I do:

    1. Create a drawable that has a transparent background so that I can see the desktop through it.
    2. Draw a bitmap.
    3. Enable blending and call glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).
    4. Draw a bitmap blended over the other one.
    5. Disable blending.

    My second bitmap is blended with the first. Good. However the desktop background behind the first bitmap is also blended in!

    If I use GL_SRC_ALPHA_SATURATE then the deskktop doesn't show, but I lose the colour of my second bitmap.

    If I use glReadPixels for the area where my second bitmap is to be blended, the surface underneath is the first bitmap - not the desktop.

    What's happening here?

    Thanks for any help.

    Kind regards,
    Christopher

  2. #2
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: glBlendFunc with transparent drawables

    It isn't clear what you expect to happen. What you're describing seems reasonable.

    Perhaps you should post some images and/or state your desired effect.

  3. #3
    Member Newbie
    Join Date
    Nov 2003
    Location
    NSW
    Posts
    33

    Re: glBlendFunc with transparent drawables

    Originally posted by dorbie:
    It isn't clear what you expect to happen. What you're describing seems reasonable.

    Perhaps you should post some images and/or state your desired effect.
    Sorry for not being clearer - I don't want to see the desktop underneath - I just want to see bitmap B blended over bitmap A.

    Here's an example:
    http://www.classactionpl.com/desktopblend.jpg

    Bitmap A is an image of the world - you'll see part of Africa in the jpg - that's bitmap A. Bitmap B is the translucent rectangle. You'll see bitmap A through bitmap B (good), but you also see the desktop (those letters inside bitmap B are from the desktop behind).

    Interestingly, when I read the pixels from the area where bitmap B is to be drawn i.e. before it is drawn, the pixels read are of Bitmap A - not of any desktop behind. So it appears that Bitmap A is all that is in my framebuffer prior to blending. However if I blend then my framebuffer appears to have bitmap A and the desktop in it as a destination. I just don't understand.

    'hope this is clearer.

    -C

  4. #4
    Member Contributor
    Join Date
    Feb 2004
    Posts
    98

    Re: glBlendFunc with transparent drawables

    The drawable area's opacity is determined by the alpha value of the pixel at that window location. The area where blending occurs will have an alpha value that is not fully opaque. So the desktop bleeds through. This is correct behavior.

    Set the alpha channel to full opacity over the entire portion of the drawable you want to be fully opaque.

  5. #5
    Member Newbie
    Join Date
    Nov 2003
    Location
    NSW
    Posts
    33

    Re: glBlendFunc with transparent drawables

    Originally posted by chemdog:
    The drawable area's opacity is determined by the alpha value of the pixel at that window location. The area where blending occurs will have an alpha value that is not fully opaque. So the desktop bleeds through. This is correct behavior.

    Set the alpha channel to full opacity over the entire portion of the drawable you want to be fully opaque.
    I suspected something like this: so how do I set the opacity of the drawable selectively? Disclosure: I'm using OS X here and I think that I only get the option of stating that the drawable is entirely opaque or not. Is there a gl method of selecting a portion of the drawable and making it opaque?

  6. #6
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: glBlendFunc with transparent drawables

    You can also draw alpha channels and color component channels independently of all else. With or without blending.

    glColorMask is your friend.

    Alternatively...

    If you have a windomanager composit going on based on a windowing system that uses framebuffer alpha, then just turn off blending in OpenGL altogether. Set alpha to the desired opacity on all stuff you draw and render away.

  7. #7
    Member Newbie
    Join Date
    Nov 2003
    Location
    NSW
    Posts
    33

    Re: glBlendFunc with transparent drawables

    Originally posted by dorbie:

    glColorMask is your friend.
    You know, I just discovered glColorMask(1, 1, 1, 0) and all is now well. I didn't understand that the alpha value of the resulting blend was also computed.

    What would be ideal is to blend as I want (one minus src alpha), but have the result of the blend equate to an opaque alpha value. This is what glColorMask achieves, but I'm now curious if there's a way of specifying the glBlendFunc in such a way that the resultant alpha will be 1.0.

    Cheers,
    -C

Similar Threads

  1. glBlendFunc() for transparent background
    By surfdabbler in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 08-02-2010, 04:03 AM
  2. swapping buffers on multiple drawables
    By 147-2 in forum OpenGL: Linux
    Replies: 1
    Last Post: 05-12-2008, 04:17 PM
  3. glBlendFunc help please....
    By Al Grant in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-17-2006, 10:29 PM
  4. glBlendFunc
    By alark in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 07-10-2003, 11:41 PM
  5. overlaying transparent and non transparent bitmaps
    By dodgyposse in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-13-2000, 01:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean