/* Capture function --------------------------------------------------------- */ #include "capture.h" #include "ppm.h" #include #ifdef __APPLE__ #include #else #include #endif int capture(const char *prefix, size_t width, size_t height) { static GLubyte *buffer = NULL; static size_t buffer_size = 0; static int frame_count = 0; char fname[1024]; if (buffer_size < width*height*3) { buffer_size = width*height*3; if (buffer) free(buffer); buffer = (GLubyte*)malloc(sizeof(GLubyte)*buffer_size); } glReadBuffer(GL_BACK); glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, buffer); sprintf(fname, "%s.%08d.ppm", prefix, frame_count++); return ppm_write(fname, buffer, width, height); } /* vim: set sts=4 sw=4 ts=8 ft=cpp: ----------------------------------------- */