-1

I'm searching for a function/way to make blending work only when destination pixels' (i.e. the back buffer) alpha value is greater than 0.

What i'm looking for is something like the glAlphaFunc which tests the incoming fragments, but in my case i want to test the fragments already found in the back buffer.

Any ideas?

Thank you in advance

ps. I cannot do a pixel-by-pixel test in the drawing function because this is set as a callback function to the user.

aftos
  • 7
  • 2
  • Have You tried `glBendFunc`? – Dori Apr 19 '16 at 12:45
  • Define "*make blending work"*. Do you already have a blend function? That is, are you combining the source and destination colors, or do you just want to conditionally write the source color based on whether the destination alpha is greater than zero? – Nicol Bolas Apr 19 '16 at 13:19
  • I'm trying to achieve the second one, this is, to conditionally write the source color based on whether the destination alpha is greater than zero. What i'm trying to do is to save back buffer on various textures and on demand redraw them over the back buffer (which most probably will be redrawn with something else) using the blend function (GL_SOURCE_ALPHA, GL_ONE_MINUS_SOURCE_ALPHA). – aftos Apr 20 '16 at 06:55
  • By definition alpha values are [0..1]. So always positive. Maybe explain what you want to do, instead of how you think to do it. – starmole Apr 20 '16 at 10:09

2 Answers2

0

Wait, your answer is somewhat confusing, but i think what you're looking for is something like this : opengl - blending with previous contents of framebuffer

Community
  • 1
  • 1
-1

Sorry for this, but i think it's better answering instead of commenting.

So, let me explain better giving an example.

Let's say we have to draw something (whatever the user wants, like a table) and after that (before swapping the buffers of course) we must draw over it the "saved" textures using blending.

Let's say we have to draw two transparent boxes. If those boxes are to be saved in a different texture, this can be done by:

  1. Clear the screen with (0, 0, 0, 0)
  2. set blend function (GL_ONE, GL_ZERO)
  3. draw the box
  4. save it to texture.

Now, whenever the user wants to redraw them all, he simply draws the main theme (the table) and over it draws the textures using blend function (GL_SOURCE_ALPHA, GL_ONE_MINUS_SOURCE_ALPHA).

This works fine. But if the user wants to save both boxes in one texture and the boxes overlap, how can we save the blending of those two boxes without blend them with the "cleared" background?

Summarizing, the final image of the whole painting should be a table with two boxes (let's say a yellow and a green box) over it, blended with function (GL_SOURCE_ALPHA, GL_ONE_MINUS_SOURCE_ALPHA).

aftos
  • 7
  • 2