PDA

View Full Version : Display text efficiency



RHINO
01-19-2007, 08:03 AM
I am displaying text using GLUT, and to do so I do the following:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, width, 0.0, height);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
CALL FUNCTION TO DISPLAY TEXT
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0, aspectRatio, 0.1, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
...BEGIN DRAWING 3D...

However, this doesn't seem to be very efficient at all. Is there a better way?

zeoverlord
01-19-2007, 09:12 AM
This has always worked for me, which is pretty much the same as you have, but i save my matrices so i don't have to mess with them in any other way.

...DRAW 3D...
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho( 0, width, height , 0, -1, 1 );
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
CALL FUNCTION TO DISPLAY TEXT
glMatrixMode( GL_PROJECTION );
glPopMatrix();
glMatrixMode( GL_MODELVIEW );
glPopMatrix();


anyway though it might look slightly inefficient, it's really not, unless you call this thousands of times each frame.
You should only need to do it once per frame (or a few times if your doing some fancy effects that require this).
This has really no effect on performance.

jide
01-19-2007, 09:41 AM
We generally display texts after the 3D rendering. Or disable depth test and other stuffs while rendering your text.

RHINO
01-19-2007, 07:08 PM
Thank you, for the advice. It makes sense to draw text last, and I like how you used the Push and Pop matrix instead of having to call gluPerspective.