I’m rendering approximately 150 different labels where each letter is rendered on a curve. My solution has been to render each letter separately but this is horribly slow (4 fps). Is there any way of speeding this up?
You’re not calling beginRendering() / endRendering() between each letter, are you? If you don’t do this then you should get good performance.
I do this for each label:
private void renderLabel(GL gl, TextRenderer textRenderer, String label, float[] color) {
gl.glPushMatrix();
textRenderer.setColor(color[0], color[1], color[2], color[3]);
textRenderer.begin3DRendering();
float maxW = 0.0f;
float span = 0;
for (int i = 0; i < label.length(); i++) {
float w = textRenderer.getCharWidth(label.charAt(i));
if (w > maxW) {
maxW = w;
}
span += w;
}
float angle = span * 180.0f / 2500.0f;
float step = angle / span;
float rotate = 0.0f;
gl.glRotatef(-(180.0f - angle) / 2.0f, 0, 0, 1);
for (int i = 0; i < label.length(); i++) {
char c = label.charAt(i);
float w = textRenderer.getCharWidth(c);
gl.glPushMatrix();
gl.glRotatef(-rotate, 0, 0, 1);
gl.glTranslatef(-0.86f, 0, 0);
gl.glRotatef(90, 0, 0, 1);
textRenderer.draw3D("" + c, 0, 0, 0, 0.001f);
textRenderer.flush();
gl.glPopMatrix();
rotate += step * w;
}
textRenderer.end3DRendering();
gl.glPopMatrix();
}
TextRenderer is made once. The code is not optimal and there are some magic numbers but this was the only way I could make it work
I reworked the algorithm to only call begin3DRendering() and end3DRendering() once for all labels, but there is no improvement on speed.
I profiled the application using JProfiler and it seems more than half of the slow rendering time is spent in flush()
just try not calling flush() at all. i think it is automatically called in the end3Drendering()
If I don’t call flush() then the translate and rotate transformations are not applied to each letter.
are you using the latest version of jogl (RC8) ?
try changing the value of:
setUseVertexArrays(true/false)
I updated to the current nightly build and tried setting setUseVertexArrays(true/false) but the results are the same.
Can you email me a complete test case? kenneth dot russell at sun dot com .
I was in the process of making a test case when I retried setting setUseVertexArrays(false) and now it was fast. ???