From 406d9b9f2beccb754df272679d3420fe6511e338 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Tue, 16 Mar 2021 18:10:21 +0200 Subject: [PATCH] overlapping letter bugfix --- text.cpp | 12 +++++++----- text.h | 12 ++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/text.cpp b/text.cpp index c405177..5e6a14f 100755 --- a/text.cpp +++ b/text.cpp @@ -40,7 +40,7 @@ namespace vb01{ glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - for(u32 i = 0; i < 256; i++){ + for(u16 i = 0; i < u16(0 - 1); i++){ if(FT_Load_Char(face, i, FT_LOAD_RENDER)){ cout << "Could not load glyph\n"; continue; @@ -67,14 +67,17 @@ namespace vb01{ shader->setVec2(Vector2(width, height), "screen"); shader->setVec3(node->getPosition(), "pos"); + float advanceOffset = 0; for(int i = 0; i < entry.length(); i++){ - prepareGlyphs(entry[i]); + Glyph glyph = getGlyph(entry[i]); + prepareGlyphs(glyph, advanceOffset); + advanceOffset += glyph.size.x + glyph.bearing.x; } } - void Text::prepareGlyphs(char c){ + void Text::prepareGlyphs(Glyph glyph, float advanceOffset){ Vector3 origin = node->getPosition(); - Glyph glyph = getGlyph(c); + origin.x += advanceOffset * scale; Vector2 size = glyph.size * scale, bearing = glyph.bearing * scale; float data[] = { @@ -86,7 +89,6 @@ namespace vb01{ origin.x + bearing.x, origin.y - bearing.y + size.y, 0, 1, origin.x + bearing.x, origin.y - bearing.y, 0, 0 }; - //origin.x += (glyph.advance >> 6) * scale; renderGlyphs(glyph, data, sizeof(data)); } diff --git a/text.h b/text.h index c52e6e2..02cba0b 100755 --- a/text.h +++ b/text.h @@ -1,10 +1,10 @@ #ifndef TEXT_H #define TEXT_H -#include -#include -#include"vector.h" -#include"util.h" +#include +#include +#include "vector.h" +#include "util.h" namespace vb01{ class Node; @@ -14,7 +14,7 @@ namespace vb01{ class Text{ public: struct Glyph{ - u32 ch; + u16 ch; Texture *texture = nullptr; u32 advance; Vector2 size, bearing; @@ -33,7 +33,7 @@ namespace vb01{ inline std::string getText(){return entry;} private: void initFont(std::string); - void prepareGlyphs(char); + void prepareGlyphs(Glyph, float); void renderGlyphs(Glyph, float[], u32); Glyph getGlyph(char);