Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 KB | None | 0 0
  1. #include "Application.h"
  2. #include <iostream>
  3. #include "OpenGL.h"
  4. #include "glfw3.h"
  5. #include "GameTime.h"
  6. #include "DebugRenderer.h"
  7.  
  8. using namespace igad;
  9.  
  10. Appliation::Appliation(float a_fWidth, float a_fHeight)
  11. {
  12.     m_pWindow = NULL;
  13.     m_fWidth = a_fWidth;
  14.     m_fHeight = a_fHeight;
  15. }
  16.  
  17. Appliation::~Appliation()
  18. {
  19. }
  20.  
  21. void Appliation::Run()
  22. {
  23.     if (!InitGLFW()) return;
  24.     OnCreate();
  25.  
  26.     while (!glfwWindowShouldClose(m_pWindow))
  27.     {
  28.         GameTime::Tick();
  29.  
  30.         glClearColor(0.04f, 0.16f, 0.22f, 1.0f);
  31.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  32.         glEnable(GL_CULL_FACE);
  33.         glEnable(GL_DEPTH_TEST);
  34.  
  35.         OnUpdate(GameTime::GetDeltaTime());
  36.         OnDraw();
  37.  
  38.         glfwSwapBuffers(m_pWindow);
  39.         glfwPollEvents();
  40.     }
  41.     glfwDestroyWindow(m_pWindow);
  42.     glfwTerminate();
  43. }
  44.  
  45. void Appliation::Exit() const
  46. {
  47.     glfwSetWindowShouldClose(m_pWindow, true);
  48. }
  49.  
  50. bool Appliation::InitGLFW()
  51. {
  52.     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  53.     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
  54.     glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
  55.     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  56.  
  57.     if (!glfwInit())
  58.     {
  59.         std::cout << "Failed to initialize GLFW" << std::endl;
  60.         return false;
  61.     }
  62.  
  63.     //Create glfw window
  64.     m_pWindow = glfwCreateWindow(m_fWidth, m_fHeight, "Demo", NULL, NULL);
  65.     if (m_pWindow == NULL)
  66.     {
  67.         std::cout << "Failed to create GLFW window" << std::endl;
  68.         glfwTerminate();
  69.         return false;
  70.     }
  71.     glfwMakeContextCurrent(m_pWindow);
  72.  
  73.     int major = glfwGetWindowAttrib(m_pWindow, GLFW_CONTEXT_VERSION_MAJOR);
  74.     int minor = glfwGetWindowAttrib(m_pWindow, GLFW_CONTEXT_VERSION_MINOR);
  75.     int revision = glfwGetWindowAttrib(m_pWindow, GLFW_CONTEXT_REVISION);
  76.     std::cout << "OpenGL Version " << major << "." << minor << "." << revision << std::endl;
  77.  
  78.     //Load Glad
  79.     if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
  80.     {
  81.         std::cout << "Failed to initialize GLAD" << std::endl;
  82.         return false;
  83.     }
  84.  
  85.     glViewport(0, 0, m_fWidth, m_fHeight);
  86.     return true;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement