example.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <igl/get_seconds.h>
  2. using namespace igl;
  3. #include <cstdio>
  4. #include <cmath>
  5. using namespace std;
  6. #if defined(__APPLE__)
  7. # include <GLUT/glut.h>
  8. #else
  9. # include <GL/glut.h>
  10. #endif
  11. const int width = 1088;
  12. const int height = 612;
  13. int frame_counter = 0;
  14. double start_time;
  15. // number of frames before computing fps
  16. const int frames_per_lap = 1000;
  17. void Display(void)
  18. {
  19. // Clear the screen with current background color
  20. glClearColor(
  21. fabs(sin(get_seconds())),
  22. fabs(sin(get_seconds()/3)),
  23. fabs(sin(get_seconds()/7)),
  24. 0.0);
  25. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  26. // Present frame buffer
  27. glutSwapBuffers();
  28. // Recall Display at next frame
  29. glutPostRedisplay();
  30. frame_counter++;
  31. if(frame_counter == frames_per_lap)
  32. {
  33. double elapsed_time = get_seconds()-start_time;
  34. printf("%g fps: %d frames in %g seconds\n",
  35. (double)frame_counter/elapsed_time,frame_counter,elapsed_time);
  36. // reset frame counter and timer
  37. start_time = get_seconds();
  38. frame_counter = 0;
  39. }
  40. }
  41. int main(int argc,char * argv[])
  42. {
  43. // Initialize GLUT
  44. glutInit(&argc, argv);
  45. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
  46. glutInitWindowSize(width, height);
  47. // Center window
  48. glutInitWindowPosition(
  49. glutGet(GLUT_SCREEN_WIDTH)/2-glutGet(GLUT_INIT_WINDOW_WIDTH)/2,
  50. glutGet(GLUT_SCREEN_HEIGHT)/2-glutGet(GLUT_INIT_WINDOW_HEIGHT)/2);
  51. glutCreateWindow("");
  52. glutCreateMenu(NULL);
  53. // Set GLUT callbacks
  54. glutDisplayFunc(Display);
  55. //glutReshapeFunc(Reshape);
  56. // initialize timer
  57. start_time = get_seconds();
  58. // Call the GLUT main loop
  59. glutMainLoop();
  60. return 0;
  61. }