Application.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "Application.hpp"
  2. Application::Application(int width, int height) : m_window_width(width), m_window_heigth(height)
  3. {
  4. }
  5. Application::~Application()
  6. {
  7. glfwTerminate();
  8. }
  9. void Application::init()
  10. {
  11. glfwInit();
  12. glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
  13. glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
  14. glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  15. }
  16. void Application::terminate()
  17. {
  18. glfwTerminate();
  19. }
  20. bool Application::createWindow()
  21. {
  22. window = glfwCreateWindow(m_window_width, m_window_heigth, m_appName.c_str(), nullptr, nullptr);
  23. if(window == nullptr){
  24. std::cout << "glfwCreateWindow failed" << std::endl;
  25. terminate();
  26. return false;
  27. }
  28. glfwMakeContextCurrent(window);
  29. if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
  30. {
  31. std::cout << "Failed to initialize GLAD" << std::endl;
  32. terminate();
  33. return false;
  34. }
  35. glViewport(0, 0, m_window_width, m_window_heigth);
  36. return true;
  37. }
  38. bool Application::running()
  39. {
  40. return !glfwWindowShouldClose(window);
  41. }
  42. void Application::render()
  43. {
  44. glfwSwapBuffers(window);
  45. glfwPollEvents();
  46. }