//This is pretty stand-alone code to dump the current OpenGL buffer to a PPM. //You need to provide proper width and height of the image you want //to capture. (Here its just been set to 480x480). void monitor::windowDump(void){ int i,j; FILE *fptr; static int counter = 0; //this supports animation sequences char fname[32]; unsigned char *image; int width=480, height=480, stereo=0; //Allocate our buffer for the image image = (unsigned char *) malloc(3*width*height*sizeof(char)); if (image == NULL){ fprintf(stderr,"Failed to allocate memory for image\n"); return; } glPixelStorei(GL_PACK_ALIGNMENT,1); //Open the file if (stereo) sprintf(fname,"L_%04d.raw",counter); else sprintf(fname,"C_%04d.ppm",counter); if ((fptr = fopen(fname,"w")) == NULL) { fprintf(stderr,"Failed to open file for window dump\n"); return; } // Copy the image into our buffer glReadBuffer(GL_BACK_RIGHT); glReadPixels(0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,image); //Write the raw file fprintf(fptr,"P6\n%d %d\n255\n",width,height); for (j=height-1;j>=0;j--) { for (i=0;i