Blending

I am trying to export images with transparency, ie not composite them on a white background. So … anyway. I am wondering is it possible to do this

char *fragmentTransComposite = 

	"uniform sampler2D tex1;
"
	"uniform sampler2D tex2;
"
	
	"void main()
"
	"{
"
		"float alpaTotal;
"
		"vec4 colourFinal;
"
		"vec4 colour1;
"
		"vec4 colour2;
"

		"colour1 = texture2D( tex1, gl_TexCoord[0].st );
"
		"colour2 = texture2D( tex2, gl_TexCoord[0].st );
"

		"alphaTotal = colour1.a + colour2.a;
"

		"colour1.rgb = colour1.rgb * (colour1.a/alphaTotal);
"
		"colour2.rgb = colour2.rgb * (colour2.a/alphaTotal);
"

		"colourFinal.rgb = colour1.rgb + colour2.rgb;
"
		"colourFinal.a = alphaTotal;
" // <-- will get clamped 

		"gl_FragColor = outColour;
"
	"}
";

without a shader? With just the standard blending modes.

Essentially for alpha I just want to add the values together.
For colour I want to multiply them by

SourceColour * SourceAlpha / Alpha Total
then
DestColour * DestAlpha / Alpha Total

then sum them together

Take a look at texture combiners (old pre-shaders feature):

http://www.opengl.org/wiki/Texture_Combiners

You may be able to do this all in one pass without any blending (haven’t mentally mapped it all – middle stage with sum/blend might be tricky – but the rest is garden variety register combiners). If not, you can also break into two passes.

I really wanted to do this without blitting between 2 render targets, because it gets very expensive ! But it honestly doesn’t look like it’s possible with the standard ogl blending modes.