diff options
Diffstat (limited to 'src/graphics')
-rw-r--r-- | src/graphics/Font.cpp | 18 | ||||
-rw-r--r-- | src/graphics/Shader.cpp | 4 | ||||
-rw-r--r-- | src/graphics/Sprite.cpp | 9 | ||||
-rw-r--r-- | src/graphics/Text.cpp | 4 | ||||
-rw-r--r-- | src/graphics/Texture.cpp | 28 |
5 files changed, 36 insertions, 27 deletions
diff --git a/src/graphics/Font.cpp b/src/graphics/Font.cpp index ae87625..b3ef54c 100644 --- a/src/graphics/Font.cpp +++ b/src/graphics/Font.cpp @@ -1,5 +1,6 @@ #include "../../include/mglpp/graphics/Font.hpp" #include "../../include/mglpp/graphics/Texture.hpp" +#include "../../include/mglpp/system/MemoryMappedFile.hpp" #include <string.h> namespace mgl { @@ -11,32 +12,31 @@ namespace mgl { mgl_font_unload(&font); } - bool Font::load_from_file(const char *filepath, unsigned int character_size) { + bool Font::load_from_file(const MemoryMappedFile &mapped_file, unsigned int character_size) { if(font.texture.id) return false; - return mgl_font_load_from_file(&font, filepath, character_size) == 0; + return mgl_font_load_from_file(&font, mapped_file.internal_mapped_file(), character_size) == 0; } unsigned int Font::get_character_size() const { return font.character_size; } - FontGlyph Font::get_glyph(uint32_t codepoint) const { + FontGlyph Font::get_glyph(uint32_t codepoint) { FontGlyph font_glyph; - if(font.texture.id == 0) - return font_glyph; - mgl_font_get_glyph(&font, codepoint, (mgl_font_glyph*)&font_glyph); return font_glyph; } + int Font::get_kerning(uint32_t prev_codepoint, uint32_t codepoint) { + return mgl_font_get_kerning(&font, prev_codepoint, codepoint); + } + Texture Font::get_texture() const { - if(font.texture.id == 0) - return Texture(); return Texture::reference(font.texture); } mgl_font* Font::internal_font() { return &font; } -}
\ No newline at end of file +} diff --git a/src/graphics/Shader.cpp b/src/graphics/Shader.cpp index 7775b78..0d0e651 100644 --- a/src/graphics/Shader.cpp +++ b/src/graphics/Shader.cpp @@ -25,14 +25,10 @@ namespace mgl { } bool Shader::set_uniform(const char *name, float value) { - if(!shader_program.id) - return false; return mgl_shader_program_set_uniform_float(&shader_program, name, value) == 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; } diff --git a/src/graphics/Sprite.cpp b/src/graphics/Sprite.cpp index b9066ee..e6cef73 100644 --- a/src/graphics/Sprite.cpp +++ b/src/graphics/Sprite.cpp @@ -9,7 +9,8 @@ namespace mgl { Sprite::Sprite() : Sprite(nullptr, vec2f(0.0f, 0.0f)) {} Sprite::Sprite(Texture *texture, vec2f position) : texture(texture) { - mgl_sprite_init(&sprite, texture ? texture->internal_texture() : nullptr, position.x, position.y); + mgl_sprite_init(&sprite, texture ? texture->internal_texture() : nullptr); + set_position(position); } Sprite::~Sprite() { @@ -41,14 +42,12 @@ namespace mgl { sprite.scale = { scale, scale }; } - // TODO: Implement void Sprite::set_rotation(float degrees) { - + mgl_sprite_set_rotation(&sprite, degrees); } - // TODO: Implement void Sprite::set_origin(vec2f origin) { - + mgl_sprite_set_origin(&sprite, *(mgl_vec2f*)&origin); } vec2f Sprite::get_scale() const { diff --git a/src/graphics/Text.cpp b/src/graphics/Text.cpp index 953833b..ad6fed2 100644 --- a/src/graphics/Text.cpp +++ b/src/graphics/Text.cpp @@ -76,9 +76,9 @@ namespace mgl { mgl_text_set_string(&text, this->str.c_str(), this->str.size()); } - // TODO: Implement vec2f Text::find_character_pos(size_t index) { - return vec2f(); + mgl_vec2f pos = mgl_text_find_character_pos(&text, index); + return vec2f(pos.x, pos.y); } Font* Text::get_font() { diff --git a/src/graphics/Texture.cpp b/src/graphics/Texture.cpp index cdaa3ba..f543c37 100644 --- a/src/graphics/Texture.cpp +++ b/src/graphics/Texture.cpp @@ -19,18 +19,32 @@ namespace mgl { return instance; } - bool Texture::load_from_file(const char *filepath) { + bool Texture::load_from_file(const char *filepath, const LoadOptions load_options) { if(texture.id) return false; - /* TODO: use the last arg (load options) */ - return mgl_texture_load_from_file(&texture, filepath, nullptr) == 0; + + if(mgl_texture_init(&texture) != 0) + return false; + + mgl_texture_load_options texture_load_options = { + load_options.compressed, + load_options.pixel_coordinates + }; + return mgl_texture_load_from_file(&texture, filepath, &texture_load_options) == 0; } - bool Texture::load_from_image(Image &image) { + bool Texture::load_from_image(Image &image, const LoadOptions load_options) { if(texture.id) return false; - /* TODO: use the last arg (load options) */ - return mgl_texture_load_from_image(&texture, image.internal_image(), nullptr) == 0; + + if(mgl_texture_init(&texture) != 0) + return false; + + mgl_texture_load_options texture_load_options = { + load_options.compressed, + load_options.pixel_coordinates + }; + return mgl_texture_load_from_image(&texture, image.internal_image(), &texture_load_options) == 0; } vec2i Texture::get_size() const { @@ -44,4 +58,4 @@ namespace mgl { mgl_texture* Texture::internal_texture() { return &texture; } -}
\ No newline at end of file +} |