2d texture composition

I’m implementing a graphics buffering scheme for 2d composition. I’m limited to OpenGL 1.1. I’ve decided to use copyteximage2d as the main driving force of the application (also note that this is an application which has a swing/awt/java implemntation of this very same concept).

All buffers/textures are RGBA and all drawing operations are under the the SRC_ALPHA, SRC_ALPHA_MINUS_ONE blend function.

Basically, I clear the back buffer and do all of my drawing. I then copy the image into a texture of the appropriate size. I then clear the back buffer and begin to draw again, but copy this into a different texture.

After all of this is done, I need to composite the two textures for a final image (think layers in photoshop or gimp). I’m having the problem that everything is too washed out because of the alpha values compounding and making the colors worse and worse.

Clear example:

I draw a green square on the first texture, 50% alpha. I draw a blue square on the second texture, 50%. I then composite the two textures. The blue looks more like 15% alpha than 50%.

Also note that when I clear the back buffer, I clear to color (0.0, 0.0, 0.0, 0.0). I noticed that when I draw to the buffer, the colors gets blended with the back buffer color rather then written directly.

Sorry if this doesn’t make sense, the desired effect is very much like photoshop or the gimps layering functionality.

Is this even possible with clever combinations of tex_env_mode, blendfunc and alpha test?

Yes this is possible but your problem seems to be you don’t like the answer you’re getting for your alpha averaging.

You may want to explore alpha saturate and reverse blending or perhaps accumulate alpha with independent passes and write masks.

I have to disagree with your conclusions though having done something similar, SRC_ALPHA ONE_MINUS_SRC_ALPHA is the right ‘intuitive’ thing for sorted transparent blending. Try alpha of 1.0 for opaque stuff. You could draw the images with texture alpha and adjust layer transparency with vertex alpha on the underlying polygon but this requires texturing rather than drawpixels.

Photoshop layers actually support many blending modes, including an opacity per layer independent of the mask or alpha and only the default one does what you see.

Hmm… after a bit more thought and re-reading your post your problem may be gamma correction (or the lack of it in your blend operations). Phoroshop arithmetic is blended correctly for the displays color space this is pretty complex to do in hadeware. Your hardware is basically blending in simple numerically linear space but the display applies a power function to the final result. Fixing this is pretty complex and you cold probably only approximate it in hardware with a gamma LUT into and out of each blend stage so the arithmetic operates in display linear colorspace. You could do this in an OpenGL compositing application but it would probably add significant processing overheads and require some pretty decent hardware.

thanks for the reply! I’m going to do some more testing and take everything you’ve said into account. Hopefully I’ll be back with something meaningful.