GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
int maxWidth = 0, totalHeight = 0, lines = 0;
int extraX = 0, extraY = ascent;
boolean startNewLine = false;
Texture lastBind = null;
for (int glyphIndex = 0, n = vector.getNumGlyphs(); glyphIndex < n; glyphIndex++) {
int charIndex = vector.getGlyphCharIndex(glyphIndex);
if (charIndex < startIndex) continue;
if (charIndex > endIndex) break;
int codePoint = text.codePointAt(charIndex);
Rectangle bounds = getGlyphBounds(vector, glyphIndex, codePoint);
Glyph glyph = getGlyph(vector.getGlyphCode(glyphIndex), codePoint, bounds, vector, glyphIndex);
if (startNewLine && codePoint != '\n') {
extraX = -bounds.x;
startNewLine = false;
}
Image image = glyph.getImage();
if (image == null && missingGlyph != null && glyph.isMissing()) image = missingGlyph.getImage();
if (image != null) {
// Draw glyph, only binding a new glyph page texture when necessary.
Texture texture = image.getTexture();
if (lastBind != null && lastBind != texture) {
GL.glEnd();
lastBind = null;
}
if (lastBind == null) {
texture.bind();
GL.glBegin(SGL.GL_QUADS);
lastBind = texture;
}
image.drawEmbedded(bounds.x + extraX, bounds.y + extraY, image.getWidth(), image.getHeight());
}