diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/graphics/Font.cpp | 4 | ||||
-rw-r--r-- | src/graphics/Image.cpp | 4 | ||||
-rw-r--r-- | src/graphics/Shader.cpp | 40 | ||||
-rw-r--r-- | src/window/Window.cpp | 11 |
4 files changed, 54 insertions, 5 deletions
diff --git a/src/graphics/Font.cpp b/src/graphics/Font.cpp index 52698d3..7b5dd68 100644 --- a/src/graphics/Font.cpp +++ b/src/graphics/Font.cpp @@ -9,10 +9,10 @@ namespace mgl { mgl_font_unload(&font); } - bool Font::load_from_file(const std::string &filepath, unsigned int character_size) { + bool Font::load_from_file(const char *filepath, unsigned int character_size) { if(font.texture.id) return false; - return mgl_font_load_from_file(&font, filepath.c_str(), character_size) == 0; + return mgl_font_load_from_file(&font, filepath, character_size) == 0; } unsigned int Font::get_character_size() const { diff --git a/src/graphics/Image.cpp b/src/graphics/Image.cpp index c45da15..493fad7 100644 --- a/src/graphics/Image.cpp +++ b/src/graphics/Image.cpp @@ -10,10 +10,10 @@ namespace mgl { mgl_image_unload(&image); } - bool Image::load_from_file(const std::string &filepath) { + bool Image::load_from_file(const char *filepath) { if(image.data) return false; - return mgl_image_load_from_file(&image, filepath.c_str()) == 0; + return mgl_image_load_from_file(&image, filepath) == 0; } unsigned char* Image::data() { diff --git a/src/graphics/Shader.cpp b/src/graphics/Shader.cpp new file mode 100644 index 0000000..96fe8ba --- /dev/null +++ b/src/graphics/Shader.cpp @@ -0,0 +1,40 @@ +#include "../../include/mglpp/graphics/Shader.hpp" + +namespace mgl { + Shader::Shader() { + shader_program.id = 0; + } + + Shader::~Shader() { + mgl_shader_program_deinit(&shader_program); + } + + bool Shader::load_from_file(const char *filepath, Type type) { + if(shader_program.id) + return false; + + int res = mgl_shader_program_init(&shader_program); + if(res != 0) + return false; + + res = mgl_shader_program_add_shader_from_file(&shader_program, filepath, (mgl_shader_type)type); + if(res != 0) + return false; + + return mgl_shader_program_finalize(&shader_program) == 0; + } + + bool Shader::set_uniform(const char *name, vec2f value) { + if(!shader_program.id) + return false; + return mgl_shader_program_set_uniform_vec2f(&shader_program, name, { value.x, value.y }) == 0; + } + + // static + void Shader::use(Shader *shader) { + if(shader) + mgl_shader_program_use(&shader->shader_program); + else + mgl_shader_program_use(nullptr); + } +}
\ No newline at end of file diff --git a/src/window/Window.cpp b/src/window/Window.cpp index bc1f5ac..79e015b 100644 --- a/src/window/Window.cpp +++ b/src/window/Window.cpp @@ -1,6 +1,7 @@ #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 <mgl/window/event.h> @@ -36,9 +37,13 @@ namespace mgl { mgl_window_clear(&window, mgl_color{color.r, color.g, color.b, color.a}); } - void Window::draw(Drawable &drawable) { + 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() { @@ -47,6 +52,10 @@ namespace mgl { 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 }; } |