Sign in to follow this  
Zerd

Bitmap Fonts

Recommended Posts

Hi, I am working on an implementation of a GUI system for an existing game engine. The static text controll leads me to the question how I can implement Bitmap fonts. Can someone give me a hint how these fonts basicly work and how I can implement it? Also I need to know how it is possible to use different font-sets (chinese, russian, latin). Does someone have experiance with this? Cheers Zerd

Share this post


Link to post
Share on other sites
Bitmap fonts are just (usually) one texture or bitmap, with all the letters on it. Your engine then just copy and pastes areas of this bitmap onto the screen to make strings. The advantage is that you can have any colour, textured, nicely styled fonts, the disadvantage is that you need to pre-render every letter you want to draw. That's not so bad in English, but other languages (Particularly Chinese) have a huge number of letters.

Share this post


Link to post
Share on other sites
So I would need to define an order in which the characters are arranged in the bitmap font texture?

Yes, that would probably be a little bit messy with chinese characters. The alternative would be to use the DirectX Font to render the text. But in this case I would have to install the font we want to use on each system.

What do you think would be the cleaner way to do it?

Share this post


Link to post
Share on other sites
Quote:
Original post by Zerd
So I would need to define an order in which the characters are arranged in the bitmap font texture?

Yes, that would probably be a little bit messy with chinese characters. The alternative would be to use the DirectX Font to render the text. But in this case I would have to install the font we want to use on each system.

What do you think would be the cleaner way to do it?
I wouldn't use a bitmap font, unless you're displaying only a few fixed strings. D3DXFont is a good choice, and you can use AddFontMemResourceEx to add a font resource to the system that's private to your process. That means that you won't need to install it on the users system, and D3DXFont should be able to pick it up.

Share this post


Link to post
Share on other sites
Thank you for your answer.

I have some problems to use AddFontMemResourceEx since MSDN has not so much information about it. Also I did not find any examples how to use this function. MSDN writes that this function needs a font resource, the size of the font resource and the count of registered fonts.

I have no clue how to handle these information. How do I create a font resource when I only have the filepath+name?

- Zerd

Share this post


Link to post
Share on other sites
You should load the font from disk into a memory buffer, or include it as a resource with your application, and use LockResource(), etc to lockthe resource to get a pointer to it's memory.
That will give you a buffer and the length of the buffer, which are the first two parameters. The third parameter should be 0, and the forth is a pointer to a DWORD value that you can probably ignore (Since it's filled by the function, and is set to the number of fonts that the resource contained - which you shouldn't care about).

Share this post


Link to post
Share on other sites
I tried to use AddFontResource which is much more easy to handle. And it works nice for me.

Is there any reason why I should use AddFontMemResourceEx instead of AddFontResource?

Share this post


Link to post
Share on other sites
Quote:
Original post by Zerd
Is there any reason why I should use AddFontMemResourceEx instead of AddFontResource?
Not really. AddFontMemResourceEx lets you keep the font resource in your application or some pack file. AddFontResource() requires that the font is in a file on disk.

Share this post


Link to post
Share on other sites

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