From e2234b4afebb266878435d10267e7b162b1fe984 Mon Sep 17 00:00:00 2001 From: Mel Date: Sat, 1 Oct 2022 05:12:50 +0200 Subject: Setup window and GL functions --- src/main.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/main.cpp (limited to 'src/main.cpp') 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 +#include +#include + +#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(glewGetErrorString(error))); + throw std::runtime_error("Failed to load GL functions: " + error_string); + } +} -- cgit 1.4.1