diff options
author | Adrian Kummerlaender | 2018-05-26 13:20:47 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2018-05-26 13:21:40 +0200 |
commit | 34052b51e00c939a35294d7085cadb5111484dd3 (patch) | |
tree | 03a5b1e350e47e2aa8551393ef67b2124ad50ddb /src/glfw/window.h | |
parent | f728e4c8d202de241673a13ce61570b6acb4bba7 (diff) | |
download | computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.gz computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.bz2 computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.lz computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.xz computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.zst computicle-34052b51e00c939a35294d7085cadb5111484dd3.zip |
Separate headers into compilation units
Diffstat (limited to 'src/glfw/window.h')
-rw-r--r-- | src/glfw/window.h | 63 |
1 files changed, 27 insertions, 36 deletions
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 <string> + #include <GL/glew.h> #include <GLFW/glfw3.h> @@ -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 <class F> - void init(F f) { - glfwMakeContextCurrent(_handle); - f(); - glfwMakeContextCurrent(nullptr); - } + void init(F f); template <class F> - 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 <class F> +void Window::init(F f) { + glfwMakeContextCurrent(_handle); + f(); + glfwMakeContextCurrent(nullptr); +} - loop(); +template <class F> +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); +} |