Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdexcept>
- #include <iostream>
- #include <GL/glew.h>
- #include <GLFW/glfw3.h>
- #include "Context.hpp"
- int main()
- {
- if (::glfwInit() != GL_TRUE)
- {
- throw std::runtime_error("GLFW failed to initialize");
- }
- ::glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- ::glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
- ::glfwWindowHint(GLFW_OPENGL_CORE_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- auto window = glfwCreateWindow(640, 480, "Hello OpenGL", nullptr, nullptr);
- if (!window)
- {
- throw std::runtime_error("GFLW failed to create a window");
- }
- ::glfwMakeContextCurrent(window);
- const auto glewResult = glewInit();
- if (glewResult != GLEW_OK)
- {
- throw std::runtime_error("Couldn't initialize glew");
- }
- Context c(1000); // 1k triangles please
- c.init();
- double frames = 0.0;
- double elapsed_time = 0.0;
- double frame_time_point;
- while (!::glfwWindowShouldClose(window))
- {
- frame_time_point = ::glfwGetTime();
- c.draw();
- ::glfwSwapBuffers(window);
- ::glfwPollEvents();
- elapsed_time += ::glfwGetTime() - frame_time_point;
- ++frames;
- }
- const auto secondsPerFrame = elapsed_time / frames;
- const auto framesPerSecond = 1 / secondsPerFrame;
- ::glfwDestroyWindow(window);
- std::cout << framesPerSecond << std::endl;
- std::cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement