Sign in to follow this  

How do you recommend I go about using bitmap fonts?

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

Well, I've already searched through the forum a few pages and used the search function to no avail... so I hope you don't find too much pain in helping me out here. What I'm trying to do here is mess around with some fonts for my OpenGL program, and I'm trying to get a new way of going about doing it. Right now I have a function that, whenever I'm rendering text, will read from my bitmap texture and then draw the letters one at a time. How I knew where on the bitmap to render was pretty simple... I drew the characters from 0 to 256 going from top-left to bottom-right, and then came up with a formula to calculate where they were as they were all in perfect 8x8 cells. The only problem with this, is this leaves us with a bit of a "tt" feeling, since all the letters are perfectly spaced between each other. I'm trying to make it so some characters aren't as wide as others like 'l' being skinnier than 'B'. My first idea was to make an ascii struct that would hold a short for x, y, w, and h of a character... and then have a struct that holds 256 of these and call it a font. I then realized this would take hours to write up as I'd have to run through each letter one by one, and then if I wanted to make another font... hoo-boy. So how would you recommend I go about doing this with being able to have a custom length for each character? ... Actually, while typing this up I came up with an idea of drawing each character to the very left of their cell and do the same x/y calculations as I did before, meaning I'd only have to write up the length of each character (height isn't really necessary anyways)... but I'm still curious on some other methods of going about this, so I guess I'll make the thread anyways... and maybe get to work on this idea right now. I've already got my old version backed up, so if I get a better suggestion I can just go back from there. Thanks for your time! --Aternus

Share this post


Link to post
Share on other sites
One option that has occured to me before, assuming that your fonts are greyscale, or at least have a colour the letters don't use, is to have the letter left aligned, then a, say red, line drawn vertically down their right boundary. You could then programmatically search for this across the texture on start-up to find the width of each letter.

It means you have an extra pixel column per letter but that isn't a major consideration these days. Still a bit of a pain to set up the bitmap, but easier than creating a seperate record.

Share this post


Link to post
Share on other sites
Hah. That's pretty clever, and would definitely save me a lot of time. Wouldn't be all too hard to set up, either. And yeah they are greyscale... I don't see a point in doing it any other way unless you need more than one colour in a letter. >_>
glColor3ub hurrah!

Edit: Can't believe I missed this... thanks a lot!

Share this post


Link to post
Share on other sites

This topic is 4089 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this