aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerlaender2018-05-25 23:17:33 +0200
committerAdrian Kummerlaender2018-05-25 23:17:33 +0200
commit5157658ec0cc07d2c56c978ca010cbb78236439f (patch)
tree0601d44e6612062ccd95e020d039be6c8a9b7ed7 /src
parentb9269b2206797091a29536f4f612a793201cdda5 (diff)
downloadcomputicle-5157658ec0cc07d2c56c978ca010cbb78236439f.tar
computicle-5157658ec0cc07d2c56c978ca010cbb78236439f.tar.gz
computicle-5157658ec0cc07d2c56c978ca010cbb78236439f.tar.bz2
computicle-5157658ec0cc07d2c56c978ca010cbb78236439f.tar.lz
computicle-5157658ec0cc07d2c56c978ca010cbb78236439f.tar.xz
computicle-5157658ec0cc07d2c56c978ca010cbb78236439f.tar.zst
computicle-5157658ec0cc07d2c56c978ca010cbb78236439f.zip
Guard GLFW init and termination
Diffstat (limited to 'src')
-rw-r--r--src/glfw_guard.h20
-rw-r--r--src/main.cc16
-rw-r--r--src/window.h3
3 files changed, 30 insertions, 9 deletions
diff --git a/src/glfw_guard.h b/src/glfw_guard.h
new file mode 100644
index 0000000..37d3ffb
--- /dev/null
+++ b/src/glfw_guard.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include <GL/glew.h>
+#include <GLFW/glfw3.h>
+
+class GlfwGuard {
+private:
+ bool _good = false;
+public:
+ GlfwGuard() {
+ _good = glfwInit();
+ }
+ ~GlfwGuard() {
+ glfwTerminate();
+ }
+
+ bool isGood() const {
+ return _good;
+ }
+};
diff --git a/src/main.cc b/src/main.cc
index 7446609..b2262e6 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -1,6 +1,3 @@
-#include <GL/glew.h>
-#include <GLFW/glfw3.h>
-
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
@@ -8,6 +5,7 @@
#include <memory>
#include <algorithm>
+#include "glfw_guard.h"
#include "window.h"
#include "particle_vertex_buffer.h"
@@ -33,13 +31,13 @@ float getWorldHeight(int window_width, int window_height, float world_width) {
}
glm::mat4 getMVP(float world_width, float world_height) {
- glm::mat4 projection = glm::ortho(
+ const glm::mat4 projection = glm::ortho(
-(world_width /2), world_width/2,
-(world_height/2), world_height/2,
0.1f, 100.0f
);
- glm::mat4 view = glm::lookAt(
+ const glm::mat4 view = glm::lookAt(
glm::vec3(0,0,1),
glm::vec3(0,0,0),
glm::vec3(0,1,0)
@@ -75,8 +73,10 @@ std::string getShaderFunction(const std::string& fx, const std::string& fy) {
}
int main() {
- if( !glfwInit() ) {
- std::cerr << "Failed to initialize GLFW." << std::endl;
+ GlfwGuard glfw;
+
+ if( !glfw.isGood() ) {
+ std::cerr << "Failed to initialize GLFW." << std::endl;
return -1;
}
@@ -84,7 +84,6 @@ int main() {
if ( !window.isGood() ) {
std::cerr << "Failed to open window." << std::endl;
- glfwTerminate();
return -1;
}
@@ -191,6 +190,5 @@ int main() {
}
});
- glfwTerminate();
return 0;
}
diff --git a/src/window.h b/src/window.h
index 76f1e6a..794dd5f 100644
--- a/src/window.h
+++ b/src/window.h
@@ -1,5 +1,8 @@
#pragma once
+#include <GL/glew.h>
+#include <GLFW/glfw3.h>
+
class Window {
private:
bool _good = false;