Jump to content
  • Advertisement
Sign in to follow this  
Gumgo

Font height

This topic is 4050 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How can I find the height of text? I'm using this code to draw it:

	GLint matrix_mode;

	glGetIntegerv( GL_MATRIX_MODE, &matrix_mode );
	glMatrixMode( GL_PROJECTION );
	glPushMatrix();
	glLoadIdentity();
	glOrtho( 0, 640, 0, 480, -1, 1 );
	glMatrixMode( GL_MODELVIEW );
	glPushMatrix();
	glLoadIdentity();

	glEnable( GL_BLEND );
	glDisable( GL_TEXTURE_2D );

	glRasterPos2f( (GLfloat)posX, 480-(GLfloat)posY - font->fsize );
	glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	glColor4f( (GLfloat)color.r/255, (GLfloat)color.g/255, (GLfloat)color.b/255, (GLfloat)alpha );

	font->PrintFont( text.c_str() );

	glEnable( GL_TEXTURE_2D );
	glDisable( GL_BLEND );

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

	glPopMatrix();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(matrix_mode);




Thanks to NeHe and this is the PrintFont function

GLvoid FontClass::PrintFont( const char *text, ... )
{
	char txt[256];
	va_list ap;

	if (text == NULL)
		return;
	va_start( ap, text );
	vsprintf( txt, text, ap );
	va_end( ap );
	glPushAttrib( GL_LIST_BIT );
	glListBase( base - 32 );
	glCallLists( strlen( txt ), GL_UNSIGNED_BYTE, text );
	glPopAttrib();
}



Sorry for the briefness, I gotta go out for dinner in a moment, but how can I find the text's height in pixels? [Edited by - Gumgo on May 21, 2007 5:38:09 PM]

Share this post


Link to post
Share on other sites
Advertisement
Sorry to bump, but I need to figure this out...

Might as well add that I'm using the CreateFont function. Also, it would work just make it so the text was drawn from the top corner, not bottom (like it is currently).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!