PDA

View Full Version : Combine and Subtract pixmap



02-12-2003, 04:04 PM
How to combine two pixmaps to form a new pixmap? I am not sure if simple addition of color (r,g,b) will work.
Thanks

Deiussum
02-13-2003, 05:24 AM
Kind of depends on what kind of results you hope to achieve.

02-13-2003, 06:02 AM
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.

Deiussum
02-13-2003, 08:18 AM
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.

shinpaughp
02-13-2003, 11:05 AM
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.