Options when it come to saving a buffer?

Hey, So I coded some Methods and now I want to save the Image I made in a bin file.

How do I do it?
I mean, I’m thinking that I can declare something like:

FILE *fav;
int screen[640 * 480];

And then with that have a click of the mouse do:

glReadPixels(0,0,winWidth,winHeight,GL_RGB,GL_UNSIGNED_BYTE,screen);
sav=fopen(“c:\ est.bin”, “w+b”);
fwrite(screen, sizeof(screen), sizeof(screen)/1, sav);
fclose(sav);

would that work? Or do I have to read every pixel in the screen?

What are my options?
I’m probably overlooking something big, but I’m out of practice. =p

Thanks in advance.

That could work, however you should first set the pixel unpack setting properly (using the PixelStore commands) and use an appropriate buffer format.
This means if you e.g. want to use tightly coupled RGB components captured as unsigned bytes then you need to declare your screen array as follows:

unsigned char screen[640 * 480 * 3];

Because you need three components.

should be fine

You should call glPixelStorei(GL_PACK_ALIGNMENT, 1) before glReadPixels if you use unsigned char screen[640 * 480 * 3]; because of alignment of each scanline.

it is better explained here
http://www.opengl.org/wiki/Common_Mistakes#Texture_upload_and_pixel_reads