# a simple question about fonts

## Recommended Posts

Quicky    100
So now, i have a question... I have seen some font.bmp files in some OpenGL programs, that i have tried. How the programmer can separate those letters in that font file? example: There is a NeHe console, and there is a font file, and all those letters are in the same file, how the programmers can tell the program what letter it have to take, and print to the program? do i make myself clear ? Ps: how can i make a text: that doesn't move anywhere when i move my camera ? For example, games have an inventory usually beneath the game screen... there is Health, ammo, armor, and other those kinds of things. how can i make that kind of inventoryy bar under my camera Now this thread ends (finally) Thanks and cheers

##### Share on other sites
Kwizatz    1392
The characters have fixed size so you map the texture as a table of characters, for example, if the dimensions of a char are 8x16 the character 'a' would be at rectangle 0,0 from the dimensions "8x16" you can calculate the rectangle that covers the char (IE 0,0 8,0 8,16 0,16 same as x,y x+width,y x+width,y+height x,y+height) B would be at 8,0, etc, usually you would use ASCII values to position your characters inside the texture though, hope that makes sence.

As for always drawing the letters on the same place, you need to apply an Orthogonal projection, draw your inventory and then go back to your perspective matrix.

Here is how I do it in my GUI library:

void PreRender(){  /*    This calculation could be done durring initialization    keeping the screen width and height in global variables    to save time.  */  GLint viewport[4];  float width;  float height;  glGetIntegerv(GL_VIEWPORT, viewport);  width =  float((viewport[2]-viewport[0]))-0.375f;  height = float((viewport[3]-viewport[1]))-0.375f;  glPushAttrib(GL_ALL_ATTRIB_BITS);  glMatrixMode(GL_PROJECTION);  glPushMatrix();  glLoadIdentity();  glOrtho(-0.375f,width,height,-0.375f, 0.0f, 1.0f);  glMatrixMode(GL_MODELVIEW);  glPushMatrix();    glLoadIdentity();  /*      These should probably be checked and saved somehow, so     we can truly return to the old state in PostRender.  */  glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);  glEnable(GL_BLEND);};/** \brief Returns OpenGL to the state it was before PreRender     \sa PreRender*/void PostRender(){  glMatrixMode(GL_PROJECTION);  glPopMatrix();  glMatrixMode(GL_MODELVIEW);  glPopMatrix();  glPopAttrib(); };

So, having those you would do this:

// (Draw your game world here)
PreRender()
// (Draw your GUI here, using glVertex2i and screen coordinates)
PostRender()

and you're done.

Hope that helps.

##### Share on other sites
Psychedelico    122
i am confused about how to display the fonts. perhaps I should learn step by step