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:
int screen[640 * 480];
And then with that have a click of the mouse do:
sav=fopen(“c:\ est.bin”, “w+b”);
fwrite(screen, sizeof(screen), sizeof(screen)/1, 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.
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