Advertisement

Textured Fonts Math Question.

Started by September 05, 2002 09:34 AM
1 comment, last by Jason2Jason 22 years, 5 months ago
Hi, a while ago i made a font class using using textured quads in open gl, but the technicle side of it is fine. The only problem is that all the letters are allways one unit apart from each other (1x1 unit quads) and the textures are dead centre in it. I used bitmap font builder to generate the font and the font wisths. I want to get the letters the right widths from each other. I tried translating by the width and by doing things to the width (like multiplying it by the image size 256 divided by the number of letter on one row (256/16=0.0625)), but it didnt work. Any ideas? I''m i just stupid that I cant work this out Thanks, -J
256/16=0.0625 ???
try 256/16=16 :-))


Advertisement
If you're using textured quads, then you'll need to first of all change the width of your quads for each letter, using the widths from bitmap font builder. Otherwise, your characters will be stretched. So, for example, if a W is 18 wide and an i is 9 wide, then when you move from "W" to "i" (spelling "With" for example), you need to scale your quad by a factor of 9/18 to make it half as wide for the "i". And you need to adjust the position of the quad by width of the previous letter. So, when you're done drawing the "W" you need to move to the right by the width of the W's quad.

The character bitmap created by bitmap font builder aligns all of the characters in rows and columns, regardless of width. To find the portion of the texture for each character, start at the center of the column. The left-most edge of the character is the center of the column minus half the width of the character. The right-most edge of the character is the center of the column plus half the width of the character. These simple formulas give you the texture U coordinate for the character.

You could consider using glBitmap() to draw your font instead of textured quads. You still end up drawing a texture to the screen. The text is always aligned with the screen (billboarded) and the process of drawing a letter and moving to the proper place for the next letter (based on the true character width) can be done in a series of display lists. So all you have to do is call glCallLists() to draw the characters, never worrying about how far to move. This is covered in Chapter 8 of the OpenGL red book.

If these suggestions are not useful, I would suggest you ask this question in the OpenGL forum.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

[edited by - grhodes_at_work on September 9, 2002 12:13:21 PM]
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net

This topic is closed to new replies.

Advertisement