GLvoid glPrint(GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat x, GLfloat y, char *text, ...)
{
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if (lights)
glDisable(GL_LIGHTING); // Disable light
if (!blend) // If blend is off
{
glEnable(GL_BLEND); // Enable blending
glDisable(GL_DEPTH_TEST); // Disable Depth Testing so the text will always be "on top"
}
glDisable(GL_TEXTURE_2D); // Disable Textures, we don''t want the text textured
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glPushMatrix(); // Store The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
glOrtho(0,width,0,height,-1,1); // Set Up An Ortho Screen with no z-buffer
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glPushMatrix(); // Store The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
glColor4f(r, g, b, a);
glRasterPos2f(x, y);
char string[256]; // Holds Our String
va_list ap; // Pointer To List Of Arguments
if (text == NULL) // If There''s No Text
return; // Do Nothing
va_start(ap, text); // Parses The String For Variables
vsprintf(string, text, ap); // And Converts Symbols To Actual Numbers
va_end(ap); // Results Are Stored In Text
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(base - 32); // Sets The Base Character to 32
glCallLists((GLsizei)(strlen(string)), GL_UNSIGNED_BYTE, // Draws The Display List Text
string);
glPopAttrib(); // Pops The Display List Bits
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glPopMatrix(); // Restore The Old Projection Matrix
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glPopMatrix(); // Restore The Old Projection Matrix
glEnable(GL_TEXTURE_2D); // Enable textures
if (lights)
glEnable(GL_LIGHTING); // Enable light
if (!blend) // If blend is off
{
glDisable(GL_BLEND); // Disable blending
glEnable(GL_DEPTH_TEST); // Enable Depth Testing
}
glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Set The Blending Function For Translucency
}
Rendering text
Hi, I have some problem with this code...
It works perfectly in another program that I made, but
in my new project the text is never rendered!?
I think I might have a had a similar problem...
Try changing glRasterPos2f(), to glTranslated()
Try changing glRasterPos2f(), to glTranslated()
Have you tried wrapping your disabling of lighting and blending under a glPushAttrib?
Love means nothing to a tennis player
My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)
Found the problem... Obviously I couldnt create the bitmap fonts inside the rendering loop... I had to create them ONCE in the init function, then it worked perfect 
Thanks for the suggestions! Always great to know there are people there to help you!

Thanks for the suggestions! Always great to know there are people there to help you!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement