void BatchRenderer2D::DrawString(const std::string& text, const maths::vec3& position, const Font& font, unsigned int color) { using namespace ftgl; float ts = 0.0f; ts = SubmitTexture(font.GetID()); const maths::vec2& scale = font.GetScale(); float x = position.x; texture_font_t* ftFont = font.GetFTFont(); for (uint i = 0; i < text.length(); i++) { char c = text[i]; texture_glyph_t* glyph = texture_font_get_glyph(ftFont, c); if (glyph != NULL) { if (i > 0) { float kerning = texture_glyph_get_kerning(glyph, text[i - 1]); x += kerning / scale.x; } float x0 = x + glyph->offset_x / scale.x; float y0 = position.y + glyph->offset_y / scale.y; float x1 = x0 + glyph->width / scale.x; float y1 = y0 - glyph->height / scale.y; float u0 = glyph->s0; float v0 = glyph->t0; float u1 = glyph->s1; float v1 = glyph->t1; m_Buffer->vertex = *m_TransformationBack * maths::vec3(x0, y0, 0); m_Buffer->uv = maths::vec2(u0, v0); m_Buffer->tid = ts; m_Buffer->color = color; m_Buffer++; m_Buffer->vertex = *m_TransformationBack * maths::vec3(x0, y1, 0); m_Buffer->uv = maths::vec2(u0, v1); m_Buffer->tid = ts; m_Buffer->color = color; m_Buffer++; m_Buffer->vertex = *m_TransformationBack * maths::vec3(x1, y1, 0); m_Buffer->uv = maths::vec2(u1, v1); m_Buffer->tid = ts; m_Buffer->color = color; m_Buffer++; m_Buffer->vertex = *m_TransformationBack * maths::vec3(x1, y0, 0); m_Buffer->uv = maths::vec2(u1, v0); m_Buffer->tid = ts; m_Buffer->color = color; m_Buffer++; m_IndexCount += 6; x += glyph->advance_x / scale.x; } } }