Combine and Subtract pixmap

How to combine two pixmaps to form a new pixmap? I am not sure if simple addition of color (r,g,b) will work.

Kind of depends on what kind of results you hope to achieve.

Originally posted by Deiussum:
Kind of depends on what kind of results you hope to achieve.

The application I am doing is supposed to read a ppm file and display it as background pixmap. The I can do some drawing on top of the background. I can then save the whole display (original background pixmap + drawing) as a new pixmap. Is there anyway I can subtract the original pixmap from the new pixmap so that I can get a pixmap only containing the drawing?

Thanks a bunch.

Not really something OpenGL can do easily for you, but a simple algorithm would be:

foreach pixel
if (pixel.color == originalbackground.pixel.color)
color = someDefinedBackgroundColor

That code is going to fail where you happen to draw the same color over pixels as the background image was, though.

How are you doing the drawing over the background? With OpenGL polygons? Maybe keep track of what you draw and when trying to save “re-render” it to the backbuffer without the background image, but don’t swapbuffers to display it.

You might try using multiple layers where you draw into one layer and your original image exists in another underlying layer. Display the under layer when you want to see how it looks together, and when you use glReadPixels to combine the images for save. Hide the underlying layer when you want to only see what you have drawn.

Disclaimer: I’ve never used layers so I may be wrong in my assumptions on their use.