]> git.sesse.net Git - glcapture/blobdiff - glcapture.c
Write TGAs directly instead of flipped PPMs.
[glcapture] / glcapture.c
index bb4c36ed0ca39413346affa99162f2ecd4c771b9..e4af4083f0b2ccaeeeb3daf0f2802716cad82cc0 100644 (file)
@@ -3,7 +3,6 @@
  *
  * gcc -shared -fPIC -o glcapture.so glcapture.c -ldl
  * LD_PRELOAD=`pwd`/glcapture.so ./demo
- * for FILE in *.ppm; do convert -flip $FILE ${FILE/ppm/tga}; echo $FILE; done
  * mencoder -noskip -endpos 76.920 -ovc x264 -x264encopts bitrate=3000:pass=1 -audiofile data/Juledemo.ogg -o tufs.avi mf://\*.tga -mf fps=50 -oac mp3lame -lameopts cbr:br=128
  * mencoder -noskip -endpos 76.920 -ovc x264 -x264encopts bitrate=3000:pass=2 -audiofile data/Juledemo.ogg -o tufs.avi mf://\*.tga -mf fps=50 -oac mp3lame -lameopts cbr:br=128
  */
 #define RTLD_NEXT ((void *) -1l)
 #endif
 
-static char buf[640 * 480 * 3];
+#define WIDTH 640
+#define HEIGHT 480
+
+static char buf[WIDTH * HEIGHT * 3];
 static int frameno = 0;
 
 void glXSwapBuffers( Display *dpy, GLXDrawable drawable )
@@ -28,12 +30,21 @@ void glXSwapBuffers( Display *dpy, GLXDrawable drawable )
 
        FILE *ppm;
        char filename[256];
-       glReadPixels(0, 0, 640, 480, GL_RGB, GL_UNSIGNED_BYTE, buf);
+       glReadPixels(0, 0, WIDTH, HEIGHT, GL_BGR, GL_UNSIGNED_BYTE, buf);
 
-       sprintf(filename, "frame%05u.ppm", frameno++);
+       sprintf(filename, "frame%05u.tga", frameno++);
        ppm = fopen(filename, "w");
-       fprintf(ppm, "P6\n640 480\n255\n");
-       fwrite(buf, 640*480*3, 1, ppm);
+       fwrite("\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00", 12, 1, ppm);
+       {
+               unsigned short w = WIDTH;
+               fwrite(&w, 2, 1, ppm);
+       }
+       {
+               unsigned short h = HEIGHT;
+               fwrite(&h, 2, 1, ppm);
+       }
+       fwrite("\x18\x00", 2, 1, ppm);
+       fwrite(buf, WIDTH*HEIGHT*3, 1, ppm);
        fclose(ppm);
 
        real_swap(dpy, drawable);