How to prevent blending with background?


I am trying to create a selective blending. The intention is to render some textured planes (containing semi-translucent alpha values). If there is nothing between the planes and the background no blending should take place to ensure a correct color value of the result. The result is read from the buffer and saved to an image.

Currently I am using this code:

//clear depthbuffer and render only planes being further in the background
glClearDepth( 0.0 );
glDepthFunc( GL_GREATER );

//disable blending and render only color of the planes
glDisable( GL_BLEND );
glColorMask( true, true, true, false );


//reset depthbuffer
glClearDepth( 1.0 );
glDepthFunc( GL_LESS );

//reset to standard blending
glEnable( GL_BLEND );
glColorMask( true, true, true, true );


Actually this retrieves a correct result, but forces me to render the planes/content twice. Has someone a better solution or does someone knows an extension to achieve the result in one step?

You really need the color value ? Or you can get away with pre-multiplied alpha ?

No, pre-multiplied alpha is not an option. The rendering results is afterwards composed on a video background by a DVE-Engine.

I always though professional video compositing did the right thing and were able to use pre-multiplied alpha … guess I was wrong.

No better idea, sorry.