# Align bitmap font (nehe Lesson: 13)

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

## Recommended Posts

I'm making a font class based off the bitmap font in lesson 13 and i ran into trouble trying to align the text. Aligning the text to the left seems to work: glRasterPos2f(0.0f, 0.0f); //easy enough Aligning to the center and right are giving me trouble. My real troubles seem to lie in the fact I dont know how wide the actual characters are that im drawing (If i switched to texture mapped quads to display text i would know how wide the characters are but i dislike the quality). I am setting up the font the same as in the lesson 13.
font = CreateFont(	-size,							// Height Of Font
0,								// Width Of Font
0,								// Angle Of Escapement
0,								// Orientation Angle
FW_BOLD,						// Font Weight
FALSE,							// Italic
FALSE,							// Underline
FALSE,							// Strikeout
ANSI_CHARSET,					// Character Set Identifier
OUT_TT_PRECIS,					// Output Precision
CLIP_DEFAULT_PRECIS,			// Clipping Precision
ANTIALIASED_QUALITY,			// Output Quality
FF_DONTCARE|DEFAULT_PITCH,		// Family And Pitch
fontname);

So i try to align the text as follow: //Center glRasterPos2f( -( (strlen(text)/2) * ( m_Size * .001 )), 0.0f); //Right glRasterPos2f( -( strlen(text) * ( m_Size * .001 )), 0.0f); where m_Size is the same as the hieght param in the CreateFont function (size). My alignment seems to be off by very little and i cant figure out the offset. any ideas please share!

##### Share on other sites
I switched the font i was displaying from "fuzzy cootie" (a custom font) to "Courier New" and it seems that my alignments are correct. I guess i still have a question: how do i figure out the offset for different fonts?

##### Share on other sites
I can't see how can m_Size be the same as the height, since every character has its own width.
If you want to know how to get the width of every character, I think you should give a look at GameTutorials.com because they have a tutorial that does it.

I think you have to add the following lines of code after calling CreateFont():
int m_Width[256];SelectObject(hDC, font);           // Selects The Font We Wantif(!GetCharWidth32(hDC, 0, 255, m_Width)){	if(!GetCharWidth(hDC, 0, 255, m_Width))	{		// It didn't work	}}

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
A4L
13
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633744
• Total Posts
3013657
×