X-Git-Url: https://git.sesse.net/?p=glcapture;a=blobdiff_plain;f=glcapture.c;h=3bf71717756a7bc1ca95e1ac4b2ee81d20b175b0;hp=c67c87d9e5dfb0a29b978b0b2d5d32c0e54f42b5;hb=132ecccb96ce6f10eb0e64cc4238a0c12eb936e5;hpb=5a3def119751d78bf9055a679b186026a0adefe6 diff --git a/glcapture.c b/glcapture.c index c67c87d..3bf7171 100644 --- a/glcapture.c +++ b/glcapture.c @@ -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 */ @@ -20,6 +19,7 @@ #define WIDTH 640 #define HEIGHT 480 +#define FPS 50 static char buf[WIDTH * HEIGHT * 3]; static int frameno = 0; @@ -31,11 +31,20 @@ void glXSwapBuffers( Display *dpy, GLXDrawable drawable ) FILE *ppm; char filename[256]; - glReadPixels(0, 0, WIDTH, HEIGHT, 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\nWIDTH HEIGHT\n255\n"); + 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); @@ -45,7 +54,15 @@ void glXSwapBuffers( Display *dpy, GLXDrawable drawable ) int gettimeofday(struct timeval *tv, struct timezone *tz) { printf("gettimeofday frame %u\n", frameno); - tv->tv_sec = frameno / 50; - tv->tv_usec = ((double)(frameno % 50) / 50) * 1000000; + tv->tv_sec = frameno / FPS; + tv->tv_usec = ((double)(frameno % FPS) / FPS) * 1000000; + return 0; +} + +int clock_gettime(clockid_t clk_id, struct timespec *tp) +{ + tp->tv_sec = frameno / FPS; + tp->tv_nsec = ((double)(frameno % FPS) / FPS) * 1e9; + return 0; }