Hi, I have this code that I wrote to learn about blending in OpenGL. While I understand what the blending equation and the blend functions do, there’s still one thing I don’t get: what is the value of the destination’s alpha? Does OpenGL save the alpha of a fragment’s pixel when storing it in the framebuffer?
// render green polygon (destination)
gl::Disable(GL_BLEND);
glex::BeginQuads();
gl::Color4(0.0, 1.0, 0.0, 1.0); // is this Ad?
gl::Vertex2((GLdouble)(-size.cx), (GLdouble)(size.cy));
gl::Vertex2((GLdouble)(-size.cx), (GLdouble)(-size.cy));
gl::Vertex2((GLdouble)(size.cx), (GLdouble)(-size.cy));
gl::Vertex2((GLdouble)(size.cx), (GLdouble)(size.cy));
gl::End();
// render white polygon (source), but using blending
// subtract dest (green) from source. result
// should be purple (255, 0, 255).
gl::Enable(GL_BLEND);
gl::BlendEquation(GL_FUNC_SUBTRACT);
gl::BlendFunc(GL_ONE, GL_ONE);
glex::BeginQuads();
gl::Color4(1.0, 1.0, 1.0, 1.0); // this is As
gl::Vertex2((GLdouble)(-size.cx), (GLdouble)(size.cy));
gl::Vertex2((GLdouble)(-size.cx), (GLdouble)(-size.cy));
gl::Vertex2((GLdouble)(size.cx), (GLdouble)(-size.cy));
gl::Vertex2((GLdouble)(size.cx), (GLdouble)(size.cy));
gl::End();
// the math behind blending
// C = <1.0, 1.0, 1.0, As>*GL_ONE - <0.0, 1.0, 0.0, Ad>*GL_ONE
// C = <1.0, 0.0, 1.0, As - Ad> =
// C = <1.0, 0.0, 1.0, 0.0> (alpha is zero, shouldn't see anything???)
Thanks,
Steve