#include #define GLFW_INCLUDE_NONE #include #include #include #include #include "callbacks.h" #include "shader.h" #include "renderer.h" #define WINDOW_WIDTH 800 #define WINDOW_HEIGHT 600 void process_input(GLFWwindow* window); int main() { if (!glfwInit()) { spdlog::error("Could not intialize GLFW."); glfwTerminate(); return EXIT_FAILURE; } glfwSetErrorCallback(error_callback); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); GLFWwindow *window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "My New Window", NULL, NULL); if (!window) { spdlog::error("Could not create GLFW Window."); glfwTerminate(); return EXIT_FAILURE; } glfwMakeContextCurrent(window); if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { spdlog::error("Failed to initialize GLAD"); return EXIT_FAILURE; } glfwSetKeyCallback(window, key_callback); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Shader basic = Shader("vert.glsl", "frag.glsl"); basic.use(); glm::mat4 projection = glm::ortho(0.0f, static_cast(WINDOW_WIDTH), static_cast(WINDOW_HEIGHT), 0.0f, -1.0f, 1.0f); basic.setMatrix4("projection", projection); Renderer r = Renderer(basic); float deltaTime = 0.0f; float lastFrame = 0.0f; while (!glfwWindowShouldClose(window)) { float currentFrame = glfwGetTime(); deltaTime = currentFrame - lastFrame; lastFrame = currentFrame; glfwPollEvents(); process_input(window); glm::vec2 pos = glm::vec2(0,0); glm::vec2 size(400.0f, 300.0f); glm::vec3 color(0.5f, 0.5f, 0.5f); glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); r.draw(pos, size, 0.0f, color); glfwSwapBuffers(window); } glfwDestroyWindow(window); glfwTerminate(); return EXIT_SUCCESS; } void process_input(GLFWwindow* window) { if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); }