- print r'''
-
-static Trace::Parser parser;
-
-static void display_noop(void) {
-}
-
-#include "bmp.hpp"
-
-static void frame_complete(void) {
- ++__frame;
-
- if (__screenshots && !__reshape_window) {
- char filename[PATH_MAX];
- snprintf(filename, sizeof filename, "screenshot_%04u.bmp", __frame);
- unsigned char *pixels = new unsigned char[__window_height*__window_width*4];
- glReadPixels(0, 0, __window_width, __window_height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
- BMP::write(filename, pixels, __window_width, __window_height, __window_width*4);
- }
-
-}
-
-static void display(void) {
- Trace::Call *call;
-
- while ((call = parser.parse_call())) {
- if (call->name() == "glFlush") {
- glFlush();
- if (!double_buffer) {
- frame_complete();
- }
- }
-
- if (!retrace_call(*call)) {
- if (call->name() == "glXSwapBuffers" ||
- call->name() == "wglSwapBuffers") {
- if (double_buffer)
- glutSwapBuffers();
- else
- glFlush();
- frame_complete();
- return;
- }
- }
- }
-
- // Reached the end of trace
- glFlush();
-
- long long endTime = OS::GetTime();
- float timeInterval = (endTime - __startTime) * 1.0E-6;
-
- std::cout <<
- "Rendered " << __frame << " frames"
- " in " << timeInterval << " secs,"
- " average of " << (__frame/timeInterval) << " fps\n";
-
- glutDisplayFunc(&display_noop);
- glutIdleFunc(NULL);
-}
-
-static void idle(void) {
- if (__reshape_window) {
- // XXX: doesn't quite work
- glutReshapeWindow(__window_width, __window_height);
- __reshape_window = false;
- }
- glutPostRedisplay();
-}
-
-int main(int argc, char **argv)
-{
-
- int i;
- for (i = 1; i < argc; ++i) {
- const char *arg = argv[i];
-
- if (arg[0] != '-') {
- break;
- }
-
- if (!strcmp(arg, "--")) {
- break;
- } else if (!strcmp(arg, "-db")) {
- double_buffer = true;
- } else if (!strcmp(arg, "-s")) {
- __screenshots = true;
- } else if (!strcmp(arg, "-v")) {
- ++verbosity;
- } else {
- std::cerr << "error: unknown option " << arg << "\n";
- return 1;
- }
- }
-
- glutInit(&argc, argv);
- glutInitWindowPosition(0, 0);
- glutInitWindowSize(__window_width, __window_height);
- glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | (double_buffer ? GLUT_DOUBLE : GLUT_SINGLE));
- glutCreateWindow(argv[0]);
-
- glutDisplayFunc(&display);
- glutIdleFunc(&idle);
-
- for (GLuint h = 0; h < 1024; ++h) {
- __list_map[h] = h;
- }
-
- for ( ; i < argc; ++i) {
- if (parser.open(argv[i])) {
- __startTime = OS::GetTime();
- glutMainLoop();
- parser.close();
- }
- }
-
- return 0;
-}
-
-'''