Skip to content

Instantly share code, notes, and snippets.

@Elessar1133
Created December 11, 2016 22:20
Show Gist options
  • Save Elessar1133/9121d22f3d591d9fea0a2c91818a84ed to your computer and use it in GitHub Desktop.
Save Elessar1133/9121d22f3d591d9fea0a2c91818a84ed to your computer and use it in GitHub Desktop.
drawString function
void BatchRenderer2D::drawString(const std::string& text, const maths::vec3& position, const maths::vec4& color)
{
using namespace ftgl;
float ts = 0.0f;
bool found = false;
for (int i = 0; i < m_TextureSlots.size(); i++)
{
if (m_TextureSlots[i] == m_FTAtlas->id)
{
ts = (float)(i + 1);
found = true;
break;
}
}
if (!found)
{
if (m_TextureSlots.size() >= 32)
{
end();
flush();
begin();
}
m_TextureSlots.push_back(m_FTAtlas->id);
ts = (float)(m_TextureSlots.size());
}
m_Buffer->vertex = maths::vec3(-4, -4, 0);
m_Buffer->uv = maths::vec2(0, 1);
m_Buffer->tid = ts;
m_Buffer++;
m_Buffer->vertex = maths::vec3(-4, 4, 0);
m_Buffer->uv = maths::vec2(0, 0);
m_Buffer->tid = ts;
m_Buffer++;
m_Buffer->vertex = maths::vec3(4, 4, 0);
m_Buffer->uv = maths::vec2(1, 0);
m_Buffer->tid = ts;
m_Buffer++;
m_Buffer->vertex = maths::vec3(4, -4, 0);
m_Buffer->uv = maths::vec2(1, 1);
m_Buffer->tid = ts;
m_Buffer++;
m_IndexCount += 6;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment