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 943c08fae5e..d4309b7675d 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); - - + ofIndexType firstIndex { static_cast(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, + static_cast(firstIndex + 1), + static_cast(firstIndex + 2), + static_cast(firstIndex + 2), + static_cast(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());