PDA

View Full Version : Optimize performance for displaying text



linlin
01-27-2009, 10:03 AM
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

Keith Z. Leonard
01-27-2009, 11:36 AM
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)

zed
01-27-2009, 07:07 PM
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/

scratt
01-27-2009, 11:09 PM
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.

_NK47
01-28-2009, 07:19 AM
"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.

Nighthawk
01-28-2009, 07:33 AM
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.

_NK47
01-28-2009, 09:20 AM
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.

Nighthawk
01-29-2009, 05:07 AM
You can also render multiple lines in one draw call:
- Check the current char to render for newline character(\n).
- 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.

linlin
01-30-2009, 11:00 AM
Hi scratt,
Do you have the URL for the SDL libraries page?

Thanks,

linlin

scratt
01-31-2009, 08:51 PM
http://www.libsdl.org/libraries.php

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