Advertisement

Rendering text

Started by April 17, 2003 02:53 PM
4 comments, last by dario_s 21 years, 10 months ago
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!?

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
}
 
I think I might have a had a similar problem...
Try changing glRasterPos2f(), to glTranslated()
Advertisement
no it didnt work...
Have you tried wrapping your disabling of lighting and blending under a glPushAttrib?
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!
Glad you solved it!

But just so that next time you post code here in the forums, use the [ source ] ''code goes here [ /source ] tags... Only without the spaces... It''s much nicer to look at.

This topic is closed to new replies.

Advertisement