#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 #include #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::create(WindowHandle existing_window) { if(window.window) return false; return mgl_window_init_from_existing_window(&window, existing_window) == 0; } bool Window::poll_event(Event &event) { if(!window.window) return false; return mgl_window_poll_event(&window, (mgl_event*)&event); } void Window::clear(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) Shader::use(shader); drawable.draw(*this); if(shader) Shader::use(nullptr); } void Window::draw(const Vertex *vertices, size_t vertex_count, PrimitiveType primitive_type, Shader *shader) { // TODO: Make the opengl context active for this thread and window, if it already isn't if(shader) Shader::use(shader); mgl_context *context = mgl_get_context(); mgl_vertices_draw(context, (const mgl_vertex*)vertices, vertex_count, (mgl_primitive_type)primitive_type); if(shader) Shader::use(nullptr); } void Window::display() { if(!window.window) return; mgl_window_display(&window); } // TODO: Implement bool Window::is_open() const { return true; } // TODO: Implement bool Window::has_focus() const { return true; } // TODO: Implement void Window::close() { } // TODO: Implement void Window::set_title(const char *title) { } // TODO: Implement void Window::set_framerate_limit(unsigned int fps) { } // TODO: Implement void Window::set_key_repeat_enabled(bool enabled) { } // TODO: Implement void Window::set_cursor_visible(bool visible) { } 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 }; } WindowHandle Window::get_system_handle() const { return window.window; } }