Results 1 to 2 of 2

Thread: Alpha compositing with glBlendFuncSeparate

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    2

    Alpha compositing with glBlendFuncSeparate

    Sorry if this is a newbie question but I've been searching for an answer to this for a few hours and have come up fruitless. I'm trying to do Porter-Duff compositing using the 'over' operator and have been unable to get what I want with glBlendFuncSeparate. I should mention that I'm using premultiplied alpha, but that's not absolutely essential.

    Suppose I have a source RGBA of (0.5, 0, 0, 0.5) and a destination RGBA of (0, 0.5, 0, 0.5). My answer should be (0.5, 0.25, 0, 0.75). I believe I can get the blended color correct by passing GL_ONE, GL_ONE_MINUS_SRC_ALPHA as the first two parameters to glBlendFuncSeparate, but I can't figure out how to get the blended alpha correct. What I want is 1 - (1 - source alpha) x (1 - dest alpha), and I don't think any combination of blend flags will get me this result. Am I missing something obvious here?

    I am sorting my geometry back to front, and have called glEnable(GL_BLEND).

    I've tried resorting to converting alpha to transparency (i.e. calling glColor4f with 1 - alpha), using glBlendFuncSeparate(GL_ONE, GL_SRC_ALPHA, GL_ZERO, GL_SRC_ALPHA) with 1.0 as the alpha value to glClearColor, but that made things worse. I understand this even less, since I think the math is correct if I do things this way.

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    2

    Re: Alpha compositing with glBlendFuncSeparate

    Never mind - I have figured out that the problem actually stemmed from issues with GL_POINT_SMOOTH (I'm drawing points). With GL_POINT_SMOOTH off, converting alpha to transparency, and drawing front to back, I can get what I want with glBlendFuncSeparate(GL_DST_ALPHA, GL_ONE, GL_ZERO, GL_SRC_ALPHA).

Similar Threads

  1. glBlendFuncSeparate() link error
    By rakeshthp in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 03-22-2013, 12:12 AM
  2. Replies: 1
    Last Post: 08-03-2012, 12:13 AM
  3. glBlendFuncSeparate issue
    By thecoast47 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-21-2011, 04:51 AM
  4. Need help on 2d & 3d compositing!
    By yooyo in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 04-10-2009, 04:42 PM
  5. blending with glBlendFuncSeparate
    By soconne in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 11-03-2006, 04:24 PM

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