aboutsummaryrefslogtreecommitdiff
path: root/src/glfw/window.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/glfw/window.h')
-rw-r--r--src/glfw/window.h63
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);
+}