Saving bitmap from openGL output, difference between original and bitmap?

I am developing a scientific visualization package using Mesa5.1 on RedHat Linux 9.
One thing we want to do is generate bitmaps for distribution on the web, so I wrote code to save the output of an opengl window as a bmp file.
I expected to see the same image, possibly slightly cropped if I did something wrong.
The image is somewhat shifted, and I am not sure why, but much worse, the image is darker
Since I’m just reading rgb data, reversing the byte order and writing it into a .bmp file, I am rather confused by this. I get the same result on a time series graph where I set the color of the lines, and on a sphere mapped with a texture (map of earth) and lit.
I view the bitmap on the same machine, and the same screen as the one that the program itself is viewed. I can comment out the byte reversal code and the colors change as I would expect, but it’s still darker, and since I am just exchanging r,g,b, I don’t see what’s going wrong. I don’t do anything with alpha, is that the problem?

Anyone who cares to look at the full code, I’ll be happy to email it, but here I will only put the little snippet that calls the bmp save routine:
Image image;
int w = 1280;
int h = 1024;
image.sizeX = w;
image.sizeY = h;
int size = wh3;
image.data = new char[size];
glReadPixels(0,0,w,h, GL_RGB, GL_BYTE, image.data);
saveBMP(“test.bmp”, &image);
close();

Hehe, use GL_UNSIGNED_BYTE instead of GL_BYTE.

Oh, and watch out for glPixelStore’s GL_PACK_ALIGNMENT if your image is shifted or sheared. Default is 4 bytes.

You might want to try using an image library to save images. That gives you a lot more flexibility and confidence when it comes to saving images.

DEVil http://openil.sourceforge.net/