Просмотр исходного кода

glut speed test

Former-commit-id: 21d38552db3a6aa2a1dc55c8f80e387404931b12
jalec 13 лет назад
Родитель
Сommit
f5b671438c
2 измененных файлов с 88 добавлено и 0 удалено
  1. 21 0
      examples/glut_speed_test/Makefile
  2. 67 0
      examples/glut_speed_test/example.cpp

+ 21 - 0
examples/glut_speed_test/Makefile

@@ -0,0 +1,21 @@
+
+.PHONY: all
+
+all: example
+
+.PHONY: example
+
+igl_lib=../../
+
+CFLAGS=-g -Wall 
+inc=-I$(igl_lib)
+
+example: example.o
+	g++ $(CFLAGS) -o example example.o -framework OpenGL -framework GLUT $(lib)
+	rm example.o
+
+example.o: example.cpp
+	g++ $(CFLAGS) $(deps) -c example.cpp -o example.o $(inc)
+clean:
+	rm -f example.o
+	rm -f example

+ 67 - 0
examples/glut_speed_test/example.cpp

@@ -0,0 +1,67 @@
+#include "get_seconds.h"
+using namespace igl;
+#include <cstdio>
+#include <cmath>
+using namespace std;
+
+#if defined(__APPLE__)
+#   include <GLUT/glut.h>
+#else
+#   include <GL/glut.h>
+#endif
+
+const int width = 1088;
+const int height = 612;
+int frame_counter = 0;
+double start_time;
+// number of frames before computing fps
+const int frames_per_lap = 1000;
+
+void Display(void)
+{
+  // Clear the screen with current background color
+  glClearColor(
+    fabs(sin(get_seconds())),
+    fabs(sin(get_seconds()/3)),
+    fabs(sin(get_seconds()/7)),
+    0.0);
+  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+  // Present frame buffer
+  glutSwapBuffers();
+  // Recall Display at next frame
+  glutPostRedisplay();
+
+  frame_counter++;
+  if(frame_counter == frames_per_lap)
+  {
+    double elapsed_time = get_seconds()-start_time;
+    printf("%g fps: %d frames in %g seconds\n",
+      (double)frame_counter/elapsed_time,frame_counter,elapsed_time);
+    // reset frame counter and timer
+    start_time = get_seconds();
+    frame_counter = 0;
+  }
+}
+
+int main(int argc,char * argv[])
+{
+  // Initialize GLUT
+  glutInit(&argc, argv);
+  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
+  glutInitWindowSize(width, height);
+  // Center window
+  glutInitWindowPosition(
+      glutGet(GLUT_SCREEN_WIDTH)/2-glutGet(GLUT_INIT_WINDOW_WIDTH)/2,
+      glutGet(GLUT_SCREEN_HEIGHT)/2-glutGet(GLUT_INIT_WINDOW_HEIGHT)/2);
+  glutCreateWindow("");
+  glutCreateMenu(NULL);
+  // Set GLUT callbacks
+  glutDisplayFunc(Display);
+  //glutReshapeFunc(Reshape);
+
+  // initialize timer
+  start_time = get_seconds();
+  // Call the GLUT main loop
+  glutMainLoop();
+  return 0;
+}