Output Image to file

I use OpenGL in Linux to draw images on the screen, do a system call to xwd and convert to jpg to create a series of frames that I can then animate later. On my new mac book I can no longer use xwd to ‘grab’ the image. I am wondering if OpenGL can write each frame directly to a file so I can skip the cheesy system call and xwd?

not really.

you have to use glReadPixels to read the color values from the framebuffer; afterwards you have to create the image file by yourself. you should use uncompressed targa format (*.tga), for a start.

meanwhile…

hoppy sent me an email, asking me for some tga-generating code. here it is- again- for everybody:

void screendump(int W, int H) {
FILE   *out = fopen("screenshot.tga","wb");
char   *pixel_data = new char[3*W*H];
short  TGAhead[] = { 0, 2, 0, 0, 0, 0, W, H, 24 };

glReadBuffer(GL_FRONT);
glReadPixels(0, 0, W, H, GL_BGR, GL_UNSIGNED_BYTE, pixel_data);

fwrite(&TGAhead,sizeof(TGAhead),1,out);
fwrite(pixel_data, 3*W*H, 1, out);
fclose(out);

delete[] pixel_data; }