I’m working on a project that, currently, is displaying a set of lines on screen (at about 220fps on this laptop).
I’m now trying to use TextRenderer to draw on some text - however, with a mere 18 strings, it kills the speed to 6fps. Yet surely 18 strings isn’t that hard to display?!
Below is my text rendering class. “stringLocation” points to where the strings are located in “tpa”, which is an array which holds information about all my lines as well (it’s all parsed from file). Only some of these have text attached to them - these are singled out in initialisation to stop me either rendering a few thousand empty strings, or spending time every frame determining whether or not to display a string.
“stringFormat” describes the font and colour of the string from a set of 6 - also determined at initialisation. The arrays “font” and “colorFloatArray” hold pre-set values for these.
Anyone have any clue why it’s so slow?
public void drawText(GL gl)
{
for(int i = 0; i < stringLocation.length; i++)
{
int j = stringLocation[i];
int xTranslate = (tpa[j].x1 + tpa[j].x2) / 2;
int yTranslate = (tpa[j].y1 + tpa[j].y2) / 2;
tr = new TextRenderer(font[stringFormat[i]]);
tr.beginRendering(mapWidth, mapHeight);
tr.setColor(
colorFloatArray[stringFormat[i]][0],
colorFloatArray[stringFormat[i]][1],
colorFloatArray[stringFormat[i]][2],
1.0f);
tr.draw(
tpa[j].labelText,
xTranslate + mapXPos,
mapHeight - yTranslate - mapYPos);
tr.endRendering();
tr.flush();
}
}