PDA

View Full Version : Could someone please write me a few lines showing how to use the glut Font library?



BigShooter
10-22-2003, 04:32 PM
I realize that there are no fonts in ogl. I'm working on Solaris Unix and I'd like to use the glut Fonts to display simple data on screen (using glOrtho2d for display). I'd appreciate if someone wrote me a few lines to show how to do it...
Thank you,
Luke

mdog1234
10-22-2003, 07:09 PM
if you are using glut you can do this. I wrote a function:
void PrintFont(void *font, const char* string, int x, int y)
{

if (string && strlen(string))
{
glPushMatrix( );
glLoadIdentity( );
glRasterPos2d( x, y );
while (*string)
{
//glut way for font.

glutBitmapCharacter(font, *string);
string++;
}
glPopMatrix( );
}
}

when calling PrintFont you would do this:
PrintFont(GLUT_BITMAP_HELVETICA_12, "your string here");

I also made a function that positions the text in 2d space(you can not position it in z here) using masking so it is always on the screen

void BeginText()
{
glMatrixMode( GL_PROJECTION );
glPushMatrix( );
glLoadIdentity( ); //WIDTH being width of screen and HEIGHT being height of screen
glOrtho( 0,WIDTH, 0, HEIGHT, -1, 1 );
glMatrixMode( GL_MODELVIEW );
}

void EndText()
{
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW); }
so then to draw the font you would do

//150, 0 being 150 width, 0 height
BeginText()
PrintFont(GLUT_BITMAP_HELVETICA_12, "your string here", 150, 0);
EndText();


this is bitmap fonts but there are fonts called stroke fonts but these look better. GLUT_BITMAP_HELVETICA_12 is just one font you can use. There arent many but do a google to find them all

[This message has been edited by mdog1234 (edited 10-22-2003).]

[This message has been edited by mdog1234 (edited 10-22-2003).]

BigShooter
10-22-2003, 08:43 PM
Thank you for taking your time to help me out.

Luke