Jump to content
  • Advertisement
Sign in to follow this  
eRig

Align bitmap font (nehe Lesson: 13)

This topic is 5033 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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 Want
if(!GetCharWidth32(hDC, 0, 255, m_Width))
{
if(!GetCharWidth(hDC, 0, 255, m_Width))
{
// It didn't work
}
}


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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!