This is related to my last question. To get this image:
I draw a white background (color =
(1, 1, 1, 1)
).I render-to-texture the two upper-left squares with color =
(1, 0, 0, .8)
and blend function(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
, and then draw the texture with color =(1, 1, 1, 1)
and blend function(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
.I draw the lower-right square with color =
(1, 0, 0, .8)
and blend function(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
.
By my calculation, the render-to-texture squares should have color
.8 * (1, 0, 0, .8) + (1 - .8) * (0, 0, 0, 0) = (.8, 0, 0, .64)
and so after drawing that texture on the white background, they should have color
(.8, 0, 0, .64) + (1 - .8) * (1, 1, 1, 1) = (1, .2, .2, .84)
and the lower-right square should have color
.8 * (1, 0, 0, .8) + (1 - .8) * (1, 1, 1, 1) = (1, .2, .2, .84)
which should look the same! Is my reasoning wrong? Is my computation wrong?
In any case, my goal is to cache some of my scene. How do I render-to-texture and then draw that texture so that it is equivalent to just drawing the scene inline?