From 34052b51e00c939a35294d7085cadb5111484dd3 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 26 May 2018 13:20:47 +0200 Subject: Separate headers into compilation units --- src/glfw/window.h | 63 ++++++++++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 36 deletions(-) (limited to 'src/glfw/window.h') diff --git a/src/glfw/window.h b/src/glfw/window.h index 794dd5f..b858e9a 100644 --- a/src/glfw/window.h +++ b/src/glfw/window.h @@ -1,5 +1,7 @@ #pragma once +#include + #include #include @@ -12,51 +14,40 @@ private: GLFWwindow* const _handle; public: - Window(const std::string& title): - _handle(glfwCreateWindow(_width, _height, title.c_str(), NULL, NULL)) { - if ( _handle != nullptr ) { - glfwMakeContextCurrent(_handle); - if ( glewInit() == GLEW_OK ) { - _good = true; - } - glfwMakeContextCurrent(nullptr); - } - } + Window(const std::string& title); - bool isGood() const { - return _good; - } - - int getWidth() const { - return _width; - } + bool isGood() const; - int getHeight() const { - return _height; - } + int getWidth() const; + int getHeight() const; template - void init(F f) { - glfwMakeContextCurrent(_handle); - f(); - glfwMakeContextCurrent(nullptr); - } + void init(F f); template - void render(F loop) { - glfwMakeContextCurrent(_handle); + void render(F loop); +}; - while ( glfwGetKey(_handle, GLFW_KEY_ESCAPE ) != GLFW_PRESS && - glfwWindowShouldClose(_handle) == 0 ) { - glfwGetWindowSize(_handle, &_width, &_height); +template +void Window::init(F f) { + glfwMakeContextCurrent(_handle); + f(); + glfwMakeContextCurrent(nullptr); +} - loop(); +template +void Window::render(F loop) { + glfwMakeContextCurrent(_handle); - glfwSwapBuffers(_handle); - glfwPollEvents(); - } + while ( glfwGetKey(_handle, GLFW_KEY_ESCAPE ) != GLFW_PRESS && + glfwWindowShouldClose(_handle) == 0 ) { + glfwGetWindowSize(_handle, &_width, &_height); - glfwMakeContextCurrent(nullptr); + loop(); + + glfwSwapBuffers(_handle); + glfwPollEvents(); } -}; + glfwMakeContextCurrent(nullptr); +} -- cgit v1.2.3