]> git.localhorst.tv Git - tacos.git/blobdiff - src/graphics/viewport.cpp
basic floor idea
[tacos.git] / src / graphics / viewport.cpp
diff --git a/src/graphics/viewport.cpp b/src/graphics/viewport.cpp
new file mode 100644 (file)
index 0000000..4ee85c8
--- /dev/null
@@ -0,0 +1,30 @@
+#include "viewport.hpp"
+
+#include <GL/glew.h>
+#include <glm/gtc/matrix_transform.hpp>
+
+
+namespace tacos {
+
+Viewport::Viewport(int w, int h)
+: width(w)
+, height(h)
+, fov(0.78539816339744830961f) // π/4
+, aspect(float(w) / float(h))
+, near(0.1f)
+, far(100.0f)
+, perspective(glm::perspective(fov, aspect, near, far))
+, ortho(glm::ortho(0.0f, float(width), float(height), 0.0f, near, far)) {
+
+}
+
+void Viewport::Resize(int w, int h) noexcept {
+       width = w;
+       height = h;
+       aspect = float(width) / float(height);
+       perspective = glm::perspective(fov, aspect, near, far);
+       ortho = glm::ortho(0.0f, float(width), float(height), 0.0f, near, far);
+       glViewport(0, 0, width, height);
+}
+
+}