#include "../../include/mglpp/window/Window.hpp" #include "../../include/mglpp/window/Event.hpp" #include "../../include/mglpp/graphics/Drawable.hpp" #include "../../include/mglpp/graphics/Shader.hpp" extern "C" { #include } namespace mgl { Window::Window() { window.window = 0; } Window::~Window() { mgl_window_deinit(&window); } bool Window::create(const char *title, int width, int height) { if(window.window) return false; return mgl_window_create_with_params(&window, title, width, height, 0) == 0; } bool Window::poll_event(Event &event) { if(!window.window) return false; /* TODO: Convert c_event to |event| */ mgl_event c_event; return mgl_window_poll_event(&window, &c_event); } void Window::clear(mgl::Color color) { if(!window.window) return; mgl_window_clear(&window, mgl_color{color.r, color.g, color.b, color.a}); } void Window::draw(Drawable &drawable, Shader *shader) { // TODO: Make the opengl context active for this thread and window, if it already isn't if(shader) mgl::Shader::use(shader); drawable.draw(*this); if(shader) mgl::Shader::use(nullptr); } void Window::display() { if(!window.window) return; mgl_window_display(&window); } vec2i Window::get_size() const { return { window.size.x, window.size.y }; } vec2i Window::get_cursor_position() const { return { window.cursor_position.x, window.cursor_position.y }; } }