Optimize performance for displaying text

Hi There,
I have to use OpenGL to create a display that contains text only knowing that OpenGL is not specialized for text rendering. I need to create a display that contains static text and dynamically updated text as follows (just an example):

static field               dynamic field
Student Name:       xxxxxx
Student ID:              xxxxxx
Student Age:          xxxxxx
Sex                          xxxxxx
Year at school:       xxxxxx

To optimize the performance, I used display list and glCallLists to display the static field. The performance improved about 10% (CPU).

Any suggestions to improve the performance for displaying the dynamic text data that I periodically received from another processor?

Thanks a lot for your help in advance !!!

linlin

This will be highly dependent upon how you are drawing the text, are you using immediate mode? What I would do is to use a font texture indexed by using “GetTextMetrics” if you are on windows, then build a quad strip for the letters into a vertex array when you get new text, and draw that array. (VBO with the dynamic flag set)

I assume the displayLists stuff is what ive seen before, where a model is created for each letter, this is a lot slower than the standard method

which is
create a texture with all the letters of the alphabet on it

see here section -> Texture Mapped Text
http://www.opengl.org/resources/features/fontsurvey/

Have a look on the SDL libraries page and you’ll find a nice little piece of code written for a Console.

It creates a texture which contains a font definition, and then draws that very fast to the screen using quads and texture offsets.

If you then enhance that by creating a big array of quads for each line and glDrawArrays it gets even faster.

That is about as quick as it gets. As has been said above you can pre-generate the texture offsets and put them into a VBO or similar, for a further speed boost.

Of course if you want to do proportional fonts / freetype etc. it gets a bit more complex, and a bit slower.

For your requirements I am thinking the SDL console code, which is three tiny files is going to be perfect, and easy to follow.

“I need to create a display that contains static text and dynamically updated …”

maybe some sort of overlay texture could help in speed. text is only rendered into texture when it changes, rest of the time just drawing a rect with texture containing the text on top of the scene.

As the previous posters said, draw one textured quad per character and use vertex arrays to render them.

You can use your existing font render code to generate the font texture with the characters in it(organized in 16x16 cells).

Foreach character:
Render character, query the rasterPos to get the width of that character, then copy it to the cell of the font texture.

true about vertex arrays. if all characters are in one texture and text is static you can build a vertex array with correct ST coordinates easiest per one text line and draw them with one call after you setup the vertex stream (glPointer calls). also you can move/rotate/scale text around with OpenGL matrix calls like any other geometry.

You can also render multiple lines in one draw call:

  • Check the current char to render for newline character(
    ).
  • If you encounter one, reset cursor.x to xStart und decrease cursor.y by lineDistance.
  • Generate quads for that line as usual until the next newline etc.

Hi scratt,
Do you have the URL for the SDL libraries page?

Thanks,

linlin

http://www.libsdl.org/libraries.php

Here’s the actual console…
http://oglconsole.sourceforge.net/