2d texture compositing, blending?

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?

Can you provide pictures of what you get along with what you expect ?

Don’t you forget to disable blending when drawing your initial textures A and B ?

About performance, try copyTexSubImage2d, it can be faster (no texture allocation, just data update).