Advertisement
Guest User

main.cpp

a guest
Aug 23rd, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include <stdexcept>
  2. #include <iostream>
  3. #include <GL/glew.h>
  4. #include <GLFW/glfw3.h>
  5. #include "Context.hpp"
  6.  
  7. int main()
  8. {
  9.     if (::glfwInit() != GL_TRUE)
  10.     {
  11.         throw std::runtime_error("GLFW failed to initialize");
  12.     }
  13.  
  14.     ::glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  15.     ::glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
  16.     ::glfwWindowHint(GLFW_OPENGL_CORE_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  17.  
  18.     auto window = glfwCreateWindow(640, 480, "Hello OpenGL", nullptr, nullptr);
  19.     if (!window)
  20.     {
  21.         throw std::runtime_error("GFLW failed to create a window");
  22.     }
  23.  
  24.     ::glfwMakeContextCurrent(window);
  25.  
  26.     const auto glewResult = glewInit();
  27.     if (glewResult != GLEW_OK)
  28.     {
  29.         throw std::runtime_error("Couldn't initialize glew");
  30.     }
  31.  
  32.     Context c(1000); // 1k triangles please
  33.     c.init();
  34.  
  35.     double frames = 0.0;
  36.     double elapsed_time = 0.0;
  37.     double frame_time_point;
  38.  
  39.     while (!::glfwWindowShouldClose(window))
  40.     {
  41.         frame_time_point = ::glfwGetTime();
  42.        
  43.         c.draw();
  44.  
  45.         ::glfwSwapBuffers(window);
  46.         ::glfwPollEvents();
  47.         elapsed_time += ::glfwGetTime() - frame_time_point;
  48.         ++frames;
  49.     }
  50.  
  51.     const auto secondsPerFrame = elapsed_time / frames;
  52.     const auto framesPerSecond = 1 / secondsPerFrame;
  53.  
  54.     ::glfwDestroyWindow(window);
  55.  
  56.     std::cout << framesPerSecond << std::endl;
  57.     std::cin.get();
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement