From 51e4beb147c26d90f5d1d632aafda353fcdf2c56 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sat, 19 Apr 2025 00:29:46 -0300 Subject: [PATCH 1/9] ofTrueTypeFont mesh insert at once --- .../graphics/ofTrueTypeFont.cpp | 68 ++++++++++--------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp index 943c08fae5e..d86cb690a07 100644 --- a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp +++ b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp @@ -298,7 +298,7 @@ void initWindows(){ char value_data_char[2048]; string fontsDir = ofGetEnv("windir"); fontsDir += "\\Fonts\\"; - + for (DWORD i = 0; i < value_count; ++i) { DWORD name_len = 2048; @@ -689,7 +689,7 @@ ofTrueTypeFont::glyph ofTrueTypeFont::loadGlyph(uint32_t utf8) const{ //----------------------------------------------------------- bool ofTrueTypeFont::load(const of::filesystem::path & filename, int fontSize, bool antialiased, bool fullCharacterSet, bool makeContours, float simplifyAmt, int dpi) { - + ofTrueTypeFontSettings settings(filename,fontSize); settings.antialiased = antialiased; settings.contours = makeContours; @@ -987,10 +987,10 @@ void ofTrueTypeFont::drawChar(uint32_t c, float x, float y, bool vFlipped) const auto props = getGlyphProperties(c); - float xmin = props.xmin+x; - float ymin = props.ymin; - float xmax = props.xmax+x; - float ymax = props.ymax; + float xmin = props.xmin+x; + float ymin = props.ymin; + float xmax = props.xmax+x; + float ymax = props.ymax; if(!vFlipped){ ymin *= -1.0; @@ -1000,26 +1000,30 @@ void ofTrueTypeFont::drawChar(uint32_t c, float x, float y, bool vFlipped) const ymin += y; ymax += y; - ofIndexType firstIndex = stringQuads.getVertices().size(); - - stringQuads.addVertex(glm::vec3(xmin,ymin,0.f)); - stringQuads.addVertex(glm::vec3(xmax,ymin,0.f)); - stringQuads.addVertex(glm::vec3(xmax,ymax,0.f)); - stringQuads.addVertex(glm::vec3(xmin,ymax,0.f)); - - stringQuads.addTexCoord(glm::vec2(props.t1,props.v1)); - stringQuads.addTexCoord(glm::vec2(props.t2,props.v1)); - stringQuads.addTexCoord(glm::vec2(props.t2,props.v2)); - stringQuads.addTexCoord(glm::vec2(props.t1,props.v2)); - - stringQuads.addIndex(firstIndex); - stringQuads.addIndex(firstIndex+1); - stringQuads.addIndex(firstIndex+2); - stringQuads.addIndex(firstIndex+2); - stringQuads.addIndex(firstIndex+3); - stringQuads.addIndex(firstIndex); - - + auto firstIndex { (unsigned int)stringQuads.getVertices().size() }; + + stringQuads.addVertices({ + { xmin, ymin, 0.f }, + { xmax, ymin, 0.f }, + { xmax, ymax, 0.f }, + { xmin, ymax, 0.f }, + }); + + stringQuads.addTexCoords({ + { props.t1, props.v1 }, + { props.t2, props.v1 }, + { props.t2, props.v2 }, + { props.t1, props.v2 } + }); + + stringQuads.addIndices({ + firstIndex, + firstIndex + 1, + firstIndex + 2, + firstIndex + 2, + firstIndex + 3, + firstIndex + }); } //----------------------------------------------------------- @@ -1188,11 +1192,11 @@ ofRectangle ofTrueTypeFont::getStringBoundingBox(const string& c, float x, float // Calculate bounding box by iterating over glyph properties // Meaning of props can be deduced from illustration at top of: // https://www.freetype.org/freetype2/docs/tutorial/step2.html - // + // // We deliberately not generate a mesh and iterate over its // vertices, as this would not correctly return spacing for // blank characters. - + float w = 0; iterateString( c, x, y, vflip, [&]( uint32_t c, glm::vec2 pos ){ auto props = getGlyphProperties( c ); @@ -1300,22 +1304,22 @@ ofTexture ofTrueTypeFont::getStringTexture(const string& str, bool vflip) const{ try{ if (c != '\n') { auto g = loadGlyph(c); - + if (c == '\t'){ auto temp = loadGlyph(' '); glyphs.push_back(temp); }else{ glyphs.push_back(g); } - + int x = pos.x + g.props.xmin; int y = pos.y; glyphPositions.emplace_back(x, y); - + if(c == '\t')lineWidth += g.props.advance + getGlyphProperties(' ').advance * spaceSize * TAB_WIDTH; else if(c == ' ')lineWidth += g.props.advance + getGlyphProperties(' ').advance * spaceSize; else if(isValidGlyph(c))lineWidth += g.props.advance + getGlyphProperties(' ').advance * (letterSpacing - 1.f); - + width = max(width, lineWidth); y += g.props.ymax; height = max(height, y + getLineHeight()); From 672deedad8d23c960af18d65b4fb022655bd1c84 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sat, 19 Apr 2025 00:30:38 -0300 Subject: [PATCH 2/9] fix indent --- libs/openFrameworks/graphics/ofTrueTypeFont.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp index d86cb690a07..99922befd9a 100644 --- a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp +++ b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp @@ -1017,12 +1017,12 @@ void ofTrueTypeFont::drawChar(uint32_t c, float x, float y, bool vFlipped) const }); stringQuads.addIndices({ - firstIndex, - firstIndex + 1, - firstIndex + 2, - firstIndex + 2, - firstIndex + 3, - firstIndex + firstIndex, + firstIndex + 1, + firstIndex + 2, + firstIndex + 2, + firstIndex + 3, + firstIndex }); } From ffd8dcf1e8436b30a262dcc7259d86944fabb21e Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sat, 19 Apr 2025 11:34:05 -0300 Subject: [PATCH 3/9] fix types --- libs/openFrameworks/graphics/ofTrueTypeFont.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp index 99922befd9a..d8fcfe3adb8 100644 --- a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp +++ b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp @@ -1000,7 +1000,7 @@ void ofTrueTypeFont::drawChar(uint32_t c, float x, float y, bool vFlipped) const ymin += y; ymax += y; - auto firstIndex { (unsigned int)stringQuads.getVertices().size() }; + auto firstIndex { (ofIndexType)stringQuads.getVertices().size() }; stringQuads.addVertices({ { xmin, ymin, 0.f }, From c9745faa7ad1473b0f66701098930bf73f08b73a Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sat, 19 Apr 2025 14:45:49 -0300 Subject: [PATCH 4/9] one more test --- libs/openFrameworks/graphics/ofTrueTypeFont.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp index d8fcfe3adb8..ed430994b97 100644 --- a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp +++ b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp @@ -1016,7 +1016,8 @@ void ofTrueTypeFont::drawChar(uint32_t c, float x, float y, bool vFlipped) const { props.t1, props.v2 } }); - stringQuads.addIndices({ + stringQuads.addIndices( + vector{ firstIndex, firstIndex + 1, firstIndex + 2, From 319d4a95631710be1b1a67afa9118afec5e442f4 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sat, 19 Apr 2025 15:01:35 -0300 Subject: [PATCH 5/9] unsigned --- libs/openFrameworks/graphics/ofTrueTypeFont.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp index ed430994b97..3b93ccc1e1d 100644 --- a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp +++ b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp @@ -1016,13 +1016,12 @@ void ofTrueTypeFont::drawChar(uint32_t c, float x, float y, bool vFlipped) const { props.t1, props.v2 } }); - stringQuads.addIndices( - vector{ + stringQuads.addIndices({ firstIndex, - firstIndex + 1, - firstIndex + 2, - firstIndex + 2, - firstIndex + 3, + firstIndex + 1u, + firstIndex + 2u, + firstIndex + 2u, + firstIndex + 3u, firstIndex }); } From 00ed262faf228ce7e686e06ffdba317437ef1cbd Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sun, 20 Apr 2025 09:16:56 -0300 Subject: [PATCH 6/9] testing --- libs/openFrameworks/graphics/ofTrueTypeFont.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp index 3b93ccc1e1d..fd310355715 100644 --- a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp +++ b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp @@ -1018,10 +1018,10 @@ void ofTrueTypeFont::drawChar(uint32_t c, float x, float y, bool vFlipped) const stringQuads.addIndices({ firstIndex, - firstIndex + 1u, - firstIndex + 2u, - firstIndex + 2u, - firstIndex + 3u, + firstIndex + 1U, + firstIndex + 2U, + firstIndex + 2U, + firstIndex + 3U, firstIndex }); } From d8fd5dacefaf738e9b3d8bc6e1e67a8e8e993a42 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sun, 20 Apr 2025 09:29:03 -0300 Subject: [PATCH 7/9] casting --- libs/openFrameworks/graphics/ofTrueTypeFont.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp index fd310355715..52d7d60e351 100644 --- a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp +++ b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp @@ -1000,7 +1000,7 @@ void ofTrueTypeFont::drawChar(uint32_t c, float x, float y, bool vFlipped) const ymin += y; ymax += y; - auto firstIndex { (ofIndexType)stringQuads.getVertices().size() }; + auto firstIndex { static_cast(stringQuads.getVertices().size()) }; stringQuads.addVertices({ { xmin, ymin, 0.f }, @@ -1018,10 +1018,10 @@ void ofTrueTypeFont::drawChar(uint32_t c, float x, float y, bool vFlipped) const stringQuads.addIndices({ firstIndex, - firstIndex + 1U, - firstIndex + 2U, - firstIndex + 2U, - firstIndex + 3U, + static_cast(firstIndex + 1U), + static_cast(firstIndex + 2U), + static_cast(firstIndex + 2U), + static_cast(firstIndex + 3U), firstIndex }); } From 841304bd7c9b76fad283beba26c276523cb258e3 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sun, 20 Apr 2025 09:56:43 -0300 Subject: [PATCH 8/9] one more --- libs/openFrameworks/graphics/ofTrueTypeFont.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp index 52d7d60e351..18828ad2e8c 100644 --- a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp +++ b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp @@ -1000,7 +1000,7 @@ void ofTrueTypeFont::drawChar(uint32_t c, float x, float y, bool vFlipped) const ymin += y; ymax += y; - auto firstIndex { static_cast(stringQuads.getVertices().size()) }; + ofIndexType firstIndex { static_cast(stringQuads.getVertices().size()) }; stringQuads.addVertices({ { xmin, ymin, 0.f }, @@ -1018,10 +1018,14 @@ void ofTrueTypeFont::drawChar(uint32_t c, float x, float y, bool vFlipped) const stringQuads.addIndices({ firstIndex, - static_cast(firstIndex + 1U), - static_cast(firstIndex + 2U), - static_cast(firstIndex + 2U), - static_cast(firstIndex + 3U), +// static_cast(firstIndex + 1), +// static_cast(firstIndex + 2), +// static_cast(firstIndex + 2), +// static_cast(firstIndex + 3), + firstIndex + 1, + firstIndex + 2, + firstIndex + 2, + firstIndex + 3, firstIndex }); } From f93d7df326b764b41014ee7b8761aeb0e1430e6b Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sun, 20 Apr 2025 18:54:56 -0300 Subject: [PATCH 9/9] fix --- libs/openFrameworks/3d/of3dPrimitives.cpp | 1 + libs/openFrameworks/graphics/ofTrueTypeFont.cpp | 12 ++++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/libs/openFrameworks/3d/of3dPrimitives.cpp b/libs/openFrameworks/3d/of3dPrimitives.cpp index e4b8bdb8206..ff74fd31f73 100644 --- a/libs/openFrameworks/3d/of3dPrimitives.cpp +++ b/libs/openFrameworks/3d/of3dPrimitives.cpp @@ -102,6 +102,7 @@ const glm::vec4& of3dPrimitive::getTexCoords() const{ //---------------------------------------------------------- vector of3dPrimitive::getIndices( int startIndex, int endIndex ) const { + vector indices; indices.assign( getMesh().getIndices().begin()+startIndex, getMesh().getIndices().begin()+endIndex ); return indices; diff --git a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp index 18828ad2e8c..d4309b7675d 100644 --- a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp +++ b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp @@ -1018,14 +1018,10 @@ void ofTrueTypeFont::drawChar(uint32_t c, float x, float y, bool vFlipped) const stringQuads.addIndices({ firstIndex, -// static_cast(firstIndex + 1), -// static_cast(firstIndex + 2), -// static_cast(firstIndex + 2), -// static_cast(firstIndex + 3), - firstIndex + 1, - firstIndex + 2, - firstIndex + 2, - firstIndex + 3, + static_cast(firstIndex + 1), + static_cast(firstIndex + 2), + static_cast(firstIndex + 2), + static_cast(firstIndex + 3), firstIndex }); }