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.