From ce061b91ae64377061ff5bf216270f3a11ed183e Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Fri, 23 Dec 2022 20:03:33 +0100 Subject: [PATCH] Cleanup the main.cpp file --- headers/window.hpp | 1 + src/main.cpp | 8 ++------ src/window.cpp | 5 +++++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/headers/window.hpp b/headers/window.hpp index 62bf0a7..fdb0fa4 100644 --- a/headers/window.hpp +++ b/headers/window.hpp @@ -25,6 +25,7 @@ class Window { void updateSize(int w, int h); void makeCurrent(); void swapBuffers(); + bool shouldClose(); private: GLFWwindow* _win; static std::map windowMap; diff --git a/src/main.cpp b/src/main.cpp index 4b1050e..25a341e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -123,9 +123,6 @@ int main() { return 1; } - // glViewport(0, 0, win.getWidth(), win.getHeight()); - // glfwSetFramebufferSizeCallback(win.getWindow(), framebuffer_size_callback); // Framebuffer - glEnable(GL_DEPTH_TEST); // Input @@ -148,7 +145,7 @@ int main() { Controller player(&win, glm::vec3(0.0f, 0.0f, 8.0f)); scene.setCamera(&player); - while (!glfwWindowShouldClose(win.getWindow())) { + while (!win.shouldClose()) { // Handle input player.processInput(scene.deltaTime); processInput(win.getWindow()); @@ -162,10 +159,9 @@ int main() { scene.render(); // glfw - glfwSwapBuffers(win.getWindow()); + win.swapBuffers(); glfwPollEvents(); } - glfwTerminate(); return 0; } diff --git a/src/window.cpp b/src/window.cpp index b432e3e..576de07 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -55,6 +55,11 @@ void Window::swapBuffers() { 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) { windowMap[win]->updateSize(width, height); }