diff --git a/text.cpp b/text.cpp index 6891e60..eab2c7f 100755 --- a/text.cpp +++ b/text.cpp @@ -4,7 +4,6 @@ #include "texture.h" #include "node.h" #include "material.h" -#include "fontReader.h" #include "fontAsset.h" #include "assetManager.h" @@ -19,18 +18,20 @@ using namespace std; namespace vb01{ Text::Text(string fontPath, wstring entry, u16 firstChar, u16 lastChar){ - initFont(fontPath, firstChar, lastChar); + applyFont(fontPath, firstChar, lastChar); setText(entry); } Text::~Text(){ + clearFont(); + glDeleteVertexArrays(1, &VAO); glDeleteBuffers(1, &VBO); } - void Text::initFont(string fontPath, u16 firstChar, u16 lastChar){ - FontReader *fontReader = FontReader::getSingleton(); - FT_Library &ft = fontReader->getFT(); + void Text::applyFont(string fontPath, u16 firstChar, u16 lastChar){ + clearFont(); + FontAsset *font = (FontAsset*)AssetManager::getSingleton()->getAsset(fontPath); FT_Face face = font->face; @@ -42,7 +43,7 @@ namespace vb01{ Glyph c; c.ch = i; - c.texture = new Texture(face, i); + c.texture = new Texture(face); c.size = Vector2(face->glyph->bitmap.width, face->glyph->bitmap.rows); c.bearing = Vector2(face->glyph->bitmap_left, face->glyph->bitmap_top); c.advance = face->glyph->advance.x; @@ -50,6 +51,13 @@ namespace vb01{ } } + void Text::clearFont(){ + while(!characters.empty()){ + delete characters[characters.size() - 1].texture; + characters.pop_back(); + } + } + void Text::update(){ Root *root = Root::getSingleton(); int width = root->getWidth(), height = root->getHeight(); diff --git a/text.h b/text.h index 1fdaa3d..e7ec20e 100755 --- a/text.h +++ b/text.h @@ -38,7 +38,8 @@ namespace vb01{ inline void setMaterial(Material *mat){this->material = mat;} Glyph* getGlyph(u16); private: - void initFont(std::string, u16, u16); + void applyFont(std::string, u16, u16 = 256); + void clearFont(); void prepareGlyphs(Glyph, Vector2); void renderGlyphs(Glyph, float[], u32); diff --git a/texture.cpp b/texture.cpp index d9b0e79..d48a8d9 100755 --- a/texture.cpp +++ b/texture.cpp @@ -127,7 +127,7 @@ namespace vb01{ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } - Texture::Texture(FT_Face &face, char ch){ + Texture::Texture(FT_Face face){ texture = new u32; glGenTextures(1, &texture[0]); diff --git a/texture.h b/texture.h index e74bc56..d9cbe9c 100755 --- a/texture.h +++ b/texture.h @@ -16,7 +16,7 @@ namespace vb01{ Texture(int, int, bool = true); Texture(std::string[], int, bool, int = 0, bool = false); Texture(int, bool = true, int = 0); - Texture(FT_Face&, char); + Texture(FT_Face); void select(int = 0, int = 0); void update(int = 0); void animate(float, KeyframeChannel);