font clearing for texts

some refactoring
This commit is contained in:
devZoGok
2022-03-02 20:24:05 +02:00
parent 35ccac66b9
commit bb8302f3ce
4 changed files with 18 additions and 9 deletions
+14 -6
View File
@@ -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();