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/guard.cc | 16 ++++++++++++++ src/glfw/guard.h | 15 +++---------- src/glfw/window.cc | 24 +++++++++++++++++++++ src/glfw/window.h | 63 +++++++++++++++++++++++------------------------------- 4 files changed, 70 insertions(+), 48 deletions(-) create mode 100644 src/glfw/guard.cc create mode 100644 src/glfw/window.cc (limited to 'src/glfw') diff --git a/src/glfw/guard.cc b/src/glfw/guard.cc new file mode 100644 index 0000000..5ba853f --- /dev/null +++ b/src/glfw/guard.cc @@ -0,0 +1,16 @@ +#include "guard.h" + +#include +#include + +GlfwGuard::GlfwGuard() { + _good = glfwInit(); +} + +GlfwGuard::~GlfwGuard() { + glfwTerminate(); +} + +bool GlfwGuard::isGood() const { + return _good; +} diff --git a/src/glfw/guard.h b/src/glfw/guard.h index 37d3ffb..f68954d 100644 --- a/src/glfw/guard.h +++ b/src/glfw/guard.h @@ -1,20 +1,11 @@ #pragma once -#include -#include - class GlfwGuard { private: bool _good = false; public: - GlfwGuard() { - _good = glfwInit(); - } - ~GlfwGuard() { - glfwTerminate(); - } + GlfwGuard(); + ~GlfwGuard(); - bool isGood() const { - return _good; - } + bool isGood() const; }; diff --git a/src/glfw/window.cc b/src/glfw/window.cc new file mode 100644 index 0000000..17fc36c --- /dev/null +++ b/src/glfw/window.cc @@ -0,0 +1,24 @@ +#include "window.h" + +Window::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); + } +} + +bool Window::isGood() const { + return _good; +} + +int Window::getWidth() const { + return _width; +} + +int Window::getHeight() const { + return _height; +} 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