How to Display 2D text on Screen, while being in 3D mode ???????????

I want to display 2D text ( ex shows FPS etc ) while running in 3D mode …

First I thought right before I go to display 2D text, I will save Current Projection matrix, and then Switch from gluPerspective() to glOrtho(), and I will be able to DIsplay the Text as If in the 2D mode, so while I move my Camera in 3D my Text will be displayed always in the same 2D position …

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

glOrtho(0,800,0,600,-1,1);
glMatrixMode(GL_MODELVIEW);

glTranslatef(400.0f, 300.0f, 0.0f);
glColor3f(1.0f, 1.0f, 1.0f);
PrintString(listBase, “TEST”);

glFlush();
SwapBuffers(g_HDC);

glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

In Other functions I setup The Font, Its type, Size, Delete etc …

This is my Print String Function

void PrintString(unsigned int base, char *str)
{
if ((base == 0) | | (str == NULL))
return;

glPushAttrib(GL_LIST_BIT);
	glListBase(base - 32);
	glCallLists(strlen(str), GL_UNSIGNED_BYTE, str);
glPopAttrib();

}

Your code looks okay to me, except that you might need to push the modelview matrix also, and then load the identity matrix before calling glTranslate. If you are using bitmap fonts, you also need to be aware of the raster position.

By the way, you should try drawing some lines with your orthographic projection. It’s possible that your text doesnt work at all.

[This message has been edited by ioquan (edited 06-13-2002).]

Try disabling GL_DEPTH_TEST

Ok It worked … I tried drawing a Polygon instead of Text in 2D, while movin my Cam in 3D…

My problem was this:

glClear();

gluLookAt( cam values );

glPushMatrix();
drawStuff();
collision=determineCollision();
glPopMatrix();

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho();
glMatrixMode(GL_MODELVIEW)

draw2DstuffHERE();

glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glFlush();

The problem with this CODE was that gluLookAt( 3D cam values ), corrupted my 2D display… Whenever I would Move in 3D, my 2D display would Appear, and Disapper whenever I would change my 3D cam coordinates… However when I put gluLookAt() withing Push/Pop Matrix with drawing the 3D object , 2D display started to work Correctly !!!

Now I will try to display some text.

I have a Question !! Right before I want to draw 2D, I call upon glMatrixMode(GL_PROJECTION)… After that I save it with glPushMatrix(), and then I reset the global ( not saved ) GL_PROJECTION matrix, for CLEAN 2D display ??? Right ?? Im trying to understand what is going on here LOL …