PDA

View Full Version : Options when it come to saving a buffer?



Antonio Gonzalez
12-16-2010, 01:57 PM
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_UNSI GNED_BYTE,screen);
sav=fopen("c:\\test.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.

aqnuep
12-16-2010, 03:12 PM
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.

ZbuffeR
12-16-2010, 04:02 PM
should be fine

V-man
12-17-2010, 11:38 AM
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