I am drawing brush strokes to an framebuffer object using the method described in the answer of this question:
opengl - blending with previous contents of framebuffer
This method correctly alpha - blends different OpenGL drawing operations into one FBO and makes sure the alpha stays correct.
It uses
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
to mix the OpenGL drawing operations (in my case brush strokes) into FBO and uses
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
to draw the final FBO (in my case a Photoshop like layer) back to the screen which removes the premultiplied alpha used in the method. This works fine for me when blitting the FBO to the screen.
However, when I want to read out the content of the FBO I cannot get rid of the premultiplied alpha. I.e. when I use
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
to draw the layer into another FBO and than use glReadPixel() to read out the content of this FBO, the content is still premultiplied.
In other words, when I draw the FBO to the screen, blending and removing the prem. alpha works, when doing the same thing and drawing into an FBO, it fails.
Here is resulting (wrong) image when I read out the FBO:
and here is the correct result when drawing the layer directly to the screen:
Thanks for any help.