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();
+2 -1
View File
@@ -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);
+1 -1
View File
@@ -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]);
+1 -1
View File
@@ -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);