View Full Version : reading color buffer to save as bitmap

mark young
08-21-2005, 02:43 PM
I have been trying to read the information from the color buffer, to save this off to a BMP format image file. When I retrieve data from the color buffer and save it to file, the objects that appear in the image are distorted. Sometimes they are perfect, sometimes a break will appear midway in the image so that the scanlines are shifted horizontally from where you would expect them, sometimes I get more or less total garbage, and sometimes the colors are simply incorrect. If I sample very small area ( 120x120 pixels ) everything works perfectly - which leads me to believe that my code is basically okay. I just don't know the arcane set of steps to make this work correctly in all cases. Since I am using multiples of 4 ( and 8 ) for my dimensions I would think that would eliminate the classic padding problem.

Any suggestions?
Thanks in advance.

- mark young

08-22-2005, 08:53 AM
Just some random ideas:

Even if ReadPixels AFAIK is to synchronize, make sure drawing is completed (glFinish).

If the color buffer is the backbuffer, check if the target window is obscured by anything. IIRC an implementation is free to not render anything in areas obscured by e.g. other windows.

Make sure you really have allocated enough memory to hold all the data returned from ReadPixels. (I'm not assuming this is the error, but it's unfortunately not too uncommon - if it doesn't apply, please disregard)

mark young
08-22-2005, 02:16 PM
Thanks Tamlin. These are excellent suggestions. I have tried these suggestions and am still having the problem. I do appreciate the advice!

- mark young / ucsc student

08-22-2005, 09:50 PM
Probably, attaching one or two samples of partially or completely distorted images to this topic could clarify the problem a bit...