Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Transparency without background

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    11

    Transparency without background

    Hi my problem:
    I dont know what background will have result image of my transparent rendering.
    glBlendFunc((GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) world fine with known background. But I cant render transparent image and send it, when I dont know bgcolor of viewer. For example if he has white background and I render image to white background, image will be blended twice and everything will be more white.

    1. solution - get somehow bgcolor with request: render transparent image with transparent background (alpha = 0), and then set every pixel with alpha > 0 to alpha = 1

    2. solution - somehow preserve color and set correct alpha channel, so it will look good with every bgcolor, but I dont have idea how.

    2.1: When I have only one transparent triangle, its easy -> I need only to set correct alpha channel and write nonmultiplied color to color buffer. (i will not use blending at all). But when I have multiple triangles on top of each other I dont know what and how to blend and how to set result alpha value.

    I really need and want to solve solution 2, how to do it in OpenGL ? IE. never blend with background, always only what I dra

    Thx Filip

  2. #2
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    490
    Quote Originally Posted by phdr_hroch View Post
    2. solution - somehow preserve color and set correct alpha channel, so it will look good with every bgcolor, but I dont have idea how.
    Create a RGBA framebuffer, clear to (0,0,0,0) (i.e. transparent), disable blending. The source alpha will be copied directly to the framebuffer.

    Quote Originally Posted by phdr_hroch View Post
    2.1: When I have only one transparent triangle, its easy -> I need only to set correct alpha channel and write nonmultiplied color to color buffer. (i will not use blending at all). But when I have multiple triangles on top of each other I dont know what and how to blend and how to set result alpha value.
    Create a RGBA framebuffer, clear to (0,0,0,0) (i.e. transparent), use glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA), source colours must use pre-multiplied alpha (e.g. yellow with 70% opacity is (0.7,0.7,0,0.7), not (1,1,0,0.7). That includes textures, so if you're loading images which don't use pre-multiplied alpha, you'll need to either multiply the R/G/B components by the alpha component after loading but before uploading the data to a texture, or perform this operation in a fragment shader.
    The resulting image will have pre-multiplied alpha, so you'll need to "un-multiply" it (i.e. divide the R/G/B channels by the alpha channel) if you're saving the result to an image format which doesn't support pre-multiplied alpha.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    11
    Thank you, I found another solution:

    I solved it now by using background with 0.0f alpha channel and glBlendFunc GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA and changed draw order.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •