summary refs log tree commit diff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-10-01 05:12:50 +0200
committerMel <einebeere@gmail.com>2022-10-01 05:13:05 +0200
commite2234b4afebb266878435d10267e7b162b1fe984 (patch)
treea582ab01a9a95a3dfd199702315d3f43c6b5b046 /src/main.cpp
downloadmeowcraft-e2234b4afebb266878435d10267e7b162b1fe984.tar.zst
meowcraft-e2234b4afebb266878435d10267e7b162b1fe984.zip
Setup window and GL functions
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..91e1b23
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,51 @@
+#include <iostream>
+#include <GL/glew.h>
+#include <GLFW/glfw3.h>
+
+#include "Window.hpp"
+
+#define APP_NAME "Meowcraft"
+
+#define WINDOW_WIDTH 1000
+#define WINDOW_HEIGHT 800
+
+void run();
+void setup_gl();
+
+int main() {
+    glfwInit();
+
+    try {
+        run();
+    } catch (std::runtime_error& error) {
+        std::cout << "An error occurred: " << error.what() << std::endl;
+        glfwTerminate();
+        return 1;
+    }
+
+    glfwTerminate();
+    return 0;
+}
+
+void run() {
+    MC::Window window(APP_NAME, WINDOW_WIDTH, WINDOW_HEIGHT);
+    setup_gl();
+
+    glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
+
+    while (!window.should_close()) {
+        window.start_frame();
+
+        if (window.key(GLFW_KEY_ESCAPE, GLFW_PRESS)) {
+            window.close();
+        }
+    }
+}
+
+void setup_gl() {
+    GLenum error;
+    if ((error = glewInit()) != GLEW_OK) {
+        std::string error_string = std::string(reinterpret_cast<const char*>(glewGetErrorString(error)));
+        throw std::runtime_error("Failed to load GL functions: " + error_string);
+    }
+}