Cleanup the main.cpp file

pull/6/head
E. Almqvist 2 years ago
parent 5e88f63273
commit ce061b91ae
  1. 1
      headers/window.hpp
  2. 8
      src/main.cpp
  3. 5
      src/window.cpp

@ -25,6 +25,7 @@ class Window {
void updateSize(int w, int h); void updateSize(int w, int h);
void makeCurrent(); void makeCurrent();
void swapBuffers(); void swapBuffers();
bool shouldClose();
private: private:
GLFWwindow* _win; GLFWwindow* _win;
static std::map<GLFWwindow*, Window*> windowMap; static std::map<GLFWwindow*, Window*> windowMap;

@ -123,9 +123,6 @@ int main() {
return 1; return 1;
} }
// glViewport(0, 0, win.getWidth(), win.getHeight());
// glfwSetFramebufferSizeCallback(win.getWindow(), framebuffer_size_callback); // Framebuffer
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
// Input // Input
@ -148,7 +145,7 @@ int main() {
Controller player(&win, glm::vec3(0.0f, 0.0f, 8.0f)); Controller player(&win, glm::vec3(0.0f, 0.0f, 8.0f));
scene.setCamera(&player); scene.setCamera(&player);
while (!glfwWindowShouldClose(win.getWindow())) { while (!win.shouldClose()) {
// Handle input // Handle input
player.processInput(scene.deltaTime); player.processInput(scene.deltaTime);
processInput(win.getWindow()); processInput(win.getWindow());
@ -162,10 +159,9 @@ int main() {
scene.render(); scene.render();
// glfw // glfw
glfwSwapBuffers(win.getWindow()); win.swapBuffers();
glfwPollEvents(); glfwPollEvents();
} }
glfwTerminate();
return 0; return 0;
} }

@ -55,6 +55,11 @@ void Window::swapBuffers() {
glfwSwapBuffers(_win); glfwSwapBuffers(_win);
} }
bool Window::shouldClose() {
return glfwWindowShouldClose(_win);
}
// Framebuffer Size Callback, called each time the window "updates"
void Window::framebufferSizeCallback(GLFWwindow* win, int width, int height) { void Window::framebufferSizeCallback(GLFWwindow* win, int width, int height) {
windowMap[win]->updateSize(width, height); windowMap[win]->updateSize(width, height);
} }

Loading…
Cancel
Save