summary refs log tree commit diff
path: root/src/main.cpp
diff options
context:
space:
mode:
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);
+    }
+}