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?
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)
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.
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.