#include // Must be included first #include "render.hpp" #include "config.hpp" #include namespace{ void handle_resize_event(GLFWwindow*, int width, int height){ debug_print("Window resized\n"); glViewport(0, 0, width, height); } } render_manager::render_manager() : m_window_close_callback(nullptr), m_input_handler(nullptr), m_main_window(nullptr){} render_manager::renderer_error render_manager::init (int width, int height, const char* title){ if(!glfwInit()){ fprintf(stderr, "[EE] failed to initialize GLFW.\n"); return RENDERER_INIT_ERROR; } glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); m_main_window = glfwCreateWindow(width, height, title, nullptr, nullptr); if(!m_main_window){ fprintf(stderr, "[EE] Could not create window\n"); return RENDERER_WINDOW_ERROR; } glfwMakeContextCurrent(m_main_window); if(gl3wInit()){ fprintf(stderr, "[EE] failed to initialize OpenGL\n"); return RENDERER_CONTEXT_ERROR; } glViewport(0, 0, width, height); debug_print("[DD] OpenGL %s, GLSL %s\n", glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION)); glfwSetFramebufferSizeCallback(m_main_window, handle_resize_event); return RENDERER_OK; } void render_manager::update(){ glfwSwapBuffers(m_main_window); glfwPollEvents(); } void render_manager::request_exit(){ if(m_window_close_callback) m_window_close_callback(); glfwSetWindowShouldClose(m_main_window, GLFW_TRUE); }