1
0
Fork 0
flightgear/Hints/screen-dump

67 lines
2.2 KiB
Text
Raw Normal View History

1999-06-15 19:54:44 +00:00
From kaszeta@me.umn.edu Tue Apr 27 12:25:04 1999
X-VM-v5-Data: ([nil nil nil nil nil nil nil nil nil]
["1377" "Tue" "27" "April" "1999" "12:25:03" "-0500" "Richard Kaszeta" "kaszeta@me.umn.edu" nil "46" "Screen Dump under OpenGL" "^From:" nil nil "4" nil nil nil nil nil]
nil)
Received: from bofh.me.umn.edu (kaszeta@bofh.me.umn.edu [134.84.18.23])
by meserv.me.umn.edu (8.9.1a/8.9.1) with ESMTP id MAA17257
for <curt@me.umn.edu>; Tue, 27 Apr 1999 12:25:04 -0500 (CDT)
Received: (from kaszeta@localhost)
by bofh.me.umn.edu (8.9.1/8.9.1) id MAA32360;
Tue, 27 Apr 1999 12:25:04 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-ID: <14117.62191.861894.721574@bofh.me.umn.edu>
X-Mailer: VM 6.47 under Emacs 19.34.1
From: Richard Kaszeta <kaszeta@me.umn.edu>
To: curt@me.umn.edu
Subject: Screen Dump under OpenGL
Date: Tue, 27 Apr 1999 12:25:03 -0500 (CDT)
Dumps the framebuffer to a .ppm file:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <GL/glut.h>
#define RGB 3 /* 3 bytes of color info per pixel */
#define RGBA 4 /* 4 bytes of color+alpha info */
void my_glDumpWindow(const char * filename, int win_width, int win_height) {
int i, j, k, q;
GLubyte *buffer;
unsigned char *ibuffer;
FILE *fp;
buffer = (GLubyte *) malloc(win_width*win_height*RGBA);
ibuffer = (unsigned char *) malloc(win_width*win_height*RGB);
/* read window contents from color buffer with glReadPixels */
glFinish();
glReadPixels(0, 0, win_width, win_height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
fp = fopen(filename, "w");
fprintf(fp, "P6\n# CREATOR: glReadPixel()\n%d %d\n%d\n",
win_width, win_height, UCHAR_MAX);
q = 0;
for (i = 0; i < win_height; i++)
for (j = 0; j < win_width; j++)
for (k = 0; k < RGB; k++)
ibuffer[q++] = (unsigned char)
*(buffer + (RGBA*((win_height-1-i)*win_width+j)+k));
fwrite(ibuffer, sizeof(unsigned char), RGB*win_width*win_height, fp);
fclose(fp);
free(buffer);
free(ibuffer);
printf("wrote file (%d x %d pixels, %d bytes)\n",
win_width, win_height, RGB*win_width*win_height);
}
--
Richard W Kaszeta PhD. Candidate and Sysadmin
bofh@me.umn.edu University of MN, ME Dept
http://www.menet.umn.edu/~kaszeta