7 static void display(void);
8 static void idle(void);
9 static void reshape(int x, int y);
10 static void keyb(unsigned char key, int x, int y);
11 static int save_image(const char *fname, unsigned char *pix, int xsz, int ysz);
13 static long start_time;
15 static long cap_frame_interval = 67;
16 static unsigned char *pixels;
18 int main(int argc, char **argv)
21 unsigned int flags = GLUT_RGB | GLUT_DOUBLE;
23 glutInitWindowSize(1280, 800);
24 glutInit(&argc, argv);
25 if(app_parse_args(argc, argv) == -1) {
31 flags |= GLUT_MULTISAMPLE;
35 glutInitDisplayMode(flags);
36 glutCreateWindow("census");
38 win_width = glutGet(GLUT_WINDOW_WIDTH);
39 win_height = glutGet(GLUT_WINDOW_HEIGHT);
43 glutSetCursor(GLUT_CURSOR_NONE);
46 glutDisplayFunc(display);
48 glutReshapeFunc(reshape);
49 glutKeyboardFunc(keyb);
51 if((env = getenv("CAPFPS")) && (cap_frame_interval = atoi(env)) > 0) {
52 cap_frame_interval = 1000 / cap_frame_interval;
54 if(!(pixels = malloc(win_width * win_height * 3))) {
55 fprintf(stderr, "failed to allocate frame capture buffer\n");
61 if(app_init() == -1) {
64 start_time = glutGet(GLUT_ELAPSED_TIME);
70 static void display(void)
73 msec += cap_frame_interval;
75 msec = glutGet(GLUT_ELAPSED_TIME) - start_time;
84 glReadPixels(0, 0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
86 sprintf(buf, "frm%03d.ppm", frame++);
87 save_image(buf, pixels, win_width, win_height);
91 assert(glGetError() == GL_NO_ERROR);
94 static void idle(void)
99 static void reshape(int x, int y)
106 static void keyb(unsigned char key, int x, int y)
108 app_keyboard(key, 1);
116 static int saved_width = 1280, saved_height = 800;
118 void app_fullscreen(void)
120 saved_width = win_width;
121 saved_height = win_height;
123 glutSetCursor(GLUT_CURSOR_NONE);
126 void app_windowed(void)
128 glutReshapeWindow(saved_width, saved_height);
129 glutSetCursor(GLUT_CURSOR_INHERIT);
132 static int save_image(const char *fname, unsigned char *pix, int xsz, int ysz)
137 if(!(fp = fopen(fname, "wb"))) {
138 fprintf(stderr, "failed to open %s for writing\n", fname);
141 fprintf(fp, "P6\n%d %d\n255\n", xsz, ysz);
143 for(i=0; i<xsz * ysz; i++) {