aboutsummaryrefslogtreecommitdiff
path: root/src/glfw
diff options
context:
space:
mode:
authorAdrian Kummerlaender2018-05-26 13:20:47 +0200
committerAdrian Kummerlaender2018-05-26 13:21:40 +0200
commit34052b51e00c939a35294d7085cadb5111484dd3 (patch)
tree03a5b1e350e47e2aa8551393ef67b2124ad50ddb /src/glfw
parentf728e4c8d202de241673a13ce61570b6acb4bba7 (diff)
downloadcomputicle-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')
-rw-r--r--src/glfw/guard.cc16
-rw-r--r--src/glfw/guard.h15
-rw-r--r--src/glfw/window.cc24
-rw-r--r--src/glfw/window.h63
4 files changed, 70 insertions, 48 deletions
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 <GL/glew.h>
+#include <GLFW/glfw3.h>
+
+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 <GL/glew.h>
-#include <GLFW/glfw3.h>
-
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 <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);
+}