#include #include #include #include "Window.hpp" #include "Mesh.hpp" #include "Binder.hpp" #include "Shader/ShaderProgram.hpp" #define APP_NAME "Meowcraft" #define WINDOW_WIDTH 1000 #define WINDOW_HEIGHT 800 void run(); void render(MC::BindableMesh&); void setup_gl(); void fix_macos_render(MC::Window&); 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); MC::Mesh shape({ {-0.5f, -0.5f, 0.0f}, {0.5f, -0.5f, 0.0f}, {-0.5f, 0.5f, 0.0f}, {0.5f, 0.5f, 0.0f}, }, {0, 1, 2, 3, 2, 1}); auto mesh = MC::Binder::load(shape); auto mesh = MC::Binder::load(quad); MC::ShaderProgram program(MC::Shader::create_fragment(), MC::Shader::create_vertex()); program.bind(); while (!window.should_close()) { window.start_frame(); #ifdef __APPLE__ fix_macos_render(window); #endif if (window.key(GLFW_KEY_ESCAPE, GLFW_PRESS)) { window.close(); } render(mesh); } } void render(MC::BindableMesh& mesh) { glClearColor(0.85f, 0.85f, 0.85f, 1.0f); // #DBDBDB glClear(GL_COLOR_BUFFER_BIT); mesh.bind(); glDrawElements(GL_TRIANGLES, mesh.size(), GL_UNSIGNED_INT, 0); mesh.unbind(); } void setup_gl() { GLenum error; if ((error = glewInit()) != GLEW_OK) { std::string error_string(reinterpret_cast(glewGetErrorString(error))); throw std::runtime_error("Failed to load GL functions: " + error_string); } } void fix_macos_render(MC::Window& window) { static bool moved = false; if(!moved) { int x, y; glfwGetWindowPos(window.get(), &x, &y); glfwSetWindowPos(window.get(), ++x, y); moved = true; } }