PDA

View Full Version : Problems with printing text when using a skybox



posixoptions
05-16-2010, 08:09 PM
I have a program that renders a heightmap and some models, the program prints text with the following function:


void printGL(char *text_buffer)
{
if(text_buffer == NULL)
return;

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


I call this function with:



glPushMatrix();
glDisable(GL_TEXTURE_2D);
glTranslatef(0.0f, 0.0f, -Z_DIFF);

glColor3f(0.0f, 1.0f, 0.0f);
glRasterPos2f(-4.8, 3.4);
sprintf(temp_buffer, "FPS: %g\n", fps);
printGL(temp_buffer);

glPopMatrix();


There is also another function for initializing the text functionality with some calls to X.

This has worked perfectly fine until I added a skybox; since I have to disable GL_BLEND for the skybox to render properly this also ruins the text making it invisible.

Now if I simply do the printGL() call subsequent to the skybox rendering, then the text will display properly. However, for the skybox to render properly I need to allow for camera rotations and translations to be performed first -- which causes the following call to the printGL() routine to be rotated and translated away to some unwanted position.

My question is simply:

How can I readily display some text that will ALWAYS appear on top of everything else, regardless of what translations, scaling, rotations and whatnot might or might not have been performed?
Either that, or some other solution to my problem would be greatly appreciated, thanks! :-)

strattonbrazil
05-17-2010, 11:04 AM
Why don't you enabled blending for the sky box and disable it after you're done to draw the text? I see you pushing the matrix stack up, but what's on it when you push it up? The skybox/camera transformation?

If I understand correctly, you need to call push matrix as you're doing, but that new matrix on the stack still has whatever is there before which would be your camera transform. Call push matrix, clear it out (the identity matrix), call your orthographic functions to place the text, and they pop the matrix. It looks like you're assuming PushMatrix clears the top matrix, which it doesn't.

posixoptions
05-17-2010, 05:41 PM
Why don't you enabled blending for the sky box and disable it after you're done to draw the text? I see you pushing the matrix stack up, but what's on it when you push it up? The skybox/camera transformation?

If I understand correctly, you need to call push matrix as you're doing, but that new matrix on the stack still has whatever is there before which would be your camera transform. Call push matrix, clear it out (the identity matrix), call your orthographic functions to place the text, and they pop the matrix. It looks like you're assuming PushMatrix clears the top matrix, which it doesn't.

Thanks, it was actually sufficient to merely do a glLoadIdentity() immediately subsequent to the glPushMatrix().