void TextureFont::RenderString(const char *str, float x, float y, const Color &color) { m_renderer->SetBlendMode(Graphics::BLEND_ALPHA); Graphics::VertexArray va(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_DIFFUSE | Graphics::ATTRIB_UV0); float px = x; float py = y; int i = 0; while (str[i]) { if (str[i] == '\n') { px = x; py += GetHeight(); i++; } else { Uint32 chr; int n = utf8_decode_char(&chr, &str[i]); assert(n); i += n; glfglyph_t *glyph = &m_glyphs[chr]; AddGlyphGeometry(&va, chr, roundf(px), py, color); if (str[i]) { Uint32 chr2; n = utf8_decode_char(&chr2, &str[i]); assert(n); FT_UInt a = FT_Get_Char_Index(m_face, chr); FT_UInt b = FT_Get_Char_Index(m_face, chr2); FT_Vector kern; FT_Get_Kerning(m_face, a, b, FT_KERNING_UNFITTED, &kern); px += float(kern.x) / 64.0; } px += glyph->advx; } } m_renderer->DrawTriangles(&va, &m_mat); }
void TextureFont::RenderString(const char *str, float x, float y, const Color &color) { PROFILE_SCOPED() m_vertices.Clear(); float alpha_f = color.a / 255.0f; const Color premult_color = Color(color.r * alpha_f, color.g * alpha_f, color.b * alpha_f, color.a); float px = x; float py = y; int i = 0; while (str[i]) { if (str[i] == '\n') { px = x; py += GetHeight(); i++; } else { Uint32 chr; int n = utf8_decode_char(&chr, &str[i]); assert(n); i += n; const Glyph &glyph = GetGlyph(chr); AddGlyphGeometry(&m_vertices, glyph, roundf(px), py, premult_color); if (str[i]) { Uint32 chr2; n = utf8_decode_char(&chr2, &str[i]); assert(n); px += GetKern(glyph, GetGlyph(chr2)); } px += glyph.advX; } } m_renderer->DrawTriangles(&m_vertices, m_renderState, m_mat.get()); }
void TextureFont::RenderString(const char *str, float x, float y, const Color &color) { m_renderer->SetBlendMode(Graphics::BLEND_ALPHA); m_vertices.Clear(); float px = x; float py = y; int i = 0; while (str[i]) { if (str[i] == '\n') { px = x; py += GetHeight(); i++; } else { Uint32 chr; int n = utf8_decode_char(&chr, &str[i]); assert(n); i += n; const glfglyph_t &glyph = GetGlyph(chr); AddGlyphGeometry(&m_vertices, glyph, roundf(px), py, color); if (str[i]) { Uint32 chr2; n = utf8_decode_char(&chr2, &str[i]); assert(n); FT_Vector kern; FT_Get_Kerning(m_face, glyph.ftIndex, GetGlyph(chr2).ftIndex, FT_KERNING_UNFITTED, &kern); px += float(kern.x) / 64.0; } px += glyph.advx; } } m_renderer->DrawTriangles(&m_vertices, m_mat.Get()); }