diff --git a/inc/game.hpp b/inc/game.hpp index 5b37d5d..e60d100 100644 --- a/inc/game.hpp +++ b/inc/game.hpp @@ -17,7 +17,13 @@ private: public: Game(int width, int height, string name); ~Game(); - void run(); + + void run(bool (*func)(Game *g)); + + GLFWwindow *getWindow(); + const char *getName(); + int getWidth(); + int getHeight(); }; #endif \ No newline at end of file diff --git a/src/game.cpp b/src/game.cpp index 6e919b5..269b072 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1,6 +1,7 @@ #include "GL/glew.h" #include "game.hpp" #include "GLFW/glfw3.h" +#include #include @@ -38,12 +39,49 @@ Game::Game(int width, int height, string name) : glEnable(GL_MULTISAMPLE); } -void Game::run() +void Game::run(bool (*func)(Game *g)) { + while(func(this)) + { + glfwGetWindowSize(this->window, &this->width, &this->height); + glViewport(0, 0, this->width, this->height); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClearColor(0.5f, 0.2f, 0.2f, 1.0f); + + glDisable(GL_MULTISAMPLE); + glfwPollEvents(); + glfwSwapBuffers(this->window); + + GLenum error = glGetError(); + if (error != glGetError()) + { + std::cerr << error << std::endl; + exit(1); + } + } } Game::~Game() { glfwTerminate(); -} \ No newline at end of file +} + +GLFWwindow *Game::getWindow() +{ + return this->window; +} +const char *Game::getName() +{ + return this->name; +} + +int Game::getWidth() +{ + return this->height; +} + +int Game::getHeight() +{ + return this->width; +} diff --git a/src/main.cpp b/src/main.cpp index 5a11d63..1e92858 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,11 @@ int main() { Game game(800, 600, "game"); - game.run(); + + auto quit = [](Game *g) { + return !glfwWindowShouldClose(g->getWindow()); + }; + + game.run(quit); return 0; } \ No newline at end of file