void Graphics::RenderText(const FontAsset& font, const std::string& text, float x, float y) { Rect verts, texCoords; glBegin(GL_QUADS); for (int i = 0; i < text.size(); i++) { char c = text[i]; if ((c >= 32) && (c < 128)) { font.GetGlyphData(c, &x, &y, verts, texCoords); glTexCoord2f(texCoords.topLeft.x, texCoords.topLeft.y); glVertex2f(verts.topLeft.x, verts.topLeft.y); glTexCoord2f(texCoords.bottomRight.x, texCoords.topLeft.y); glVertex2f(verts.bottomRight.x, verts.topLeft.y); glTexCoord2f(texCoords.bottomRight.x, texCoords.bottomRight.y); glVertex2f(verts.bottomRight.x, verts.bottomRight.y); glTexCoord2f(texCoords.topLeft.x, texCoords.bottomRight.y); glVertex2f(verts.topLeft.x, verts.bottomRight.y); } } glEnd(); }
// Render the given string, updating x and y to the point where the next character // after this string should be placed. void Graphics::RenderTextUpdatePos(const FontAsset& font, const std::wstring& text, float *x, float *y) { Rect verts, texCoords; BindFont(&font); glBegin(GL_QUADS); for (int i = 0; i < text.size(); i++) { // Render any non-control characters int unicodeCodepoint = text[i]; if (unicodeCodepoint >= 32) { font.GetGlyphData(unicodeCodepoint, x, y, verts, texCoords); glTexCoord2f(texCoords.topLeft.x, texCoords.topLeft.y); glVertex2f(verts.topLeft.x, verts.topLeft.y); glTexCoord2f(texCoords.bottomRight.x, texCoords.topLeft.y); glVertex2f(verts.bottomRight.x, verts.topLeft.y); glTexCoord2f(texCoords.bottomRight.x, texCoords.bottomRight.y); glVertex2f(verts.bottomRight.x, verts.bottomRight.y); glTexCoord2f(texCoords.topLeft.x, texCoords.bottomRight.y); glVertex2f(verts.topLeft.x, verts.bottomRight.y); } } glEnd(); }