Sign in to follow this  

Generating bitmap fonts

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

Hi, I'm trying to generate anti-aliased bitmap fonts "on the fly". The problem is GDI doesn't support the alpha channel. Is there an easy way to generate those fonts into an alpha-channel texture without a "hand-conversion" phase? (i.e. create alpha-values from gray pixels...) How did you solve it? Bye Zoomby

Share this post


Link to post
Share on other sites
You could draw black text on a white background to generate a greyscale image that you could use as an alpha channel, and then use either a pixel shader or multitexturing to alpha modulate the source texture. Essentially drawing the same text twice; once for the actual image, once for alpha.

Share this post


Link to post
Share on other sites
There are definitely ways to do what you want, along the lines of what Evil Steve suggested -- although I think his idea is even more complicated than is necessary. Once you get your 8-bit font pixels into the alpha channel of even a blank white texture, you'll be good to go with just normal quads... you can modulate the vertex color to get whatever color you need. You could even experiment with things like adding a drop shadow when you're doing the preprocessing (which is probably going to involve you locking the font texture anyways.)

I am curious how you plan to tackle the spacing and alignment issues of converting a font to a bitmapped texture; I've done it by hand many times and it isn't particularly easy! You can measure the width of each character automatically but in practice the results usually require tweaking beyond that. For instance, the letters 'b' and 'd' should both be centered about the 'o' part without regard to their 'stems'. I'd be interested if anybody knows how to solve these kinds of problems "on the fly".

Share this post


Link to post
Share on other sites
Thanks Steve!

>>to alpha modulate the source texture
Can you give me a hint how to set the texture stages to achive this?

But I think I'll also have to read the texture-topic in the DX documentation myself...

Share this post


Link to post
Share on other sites
Quote:

I am curious how you plan to tackle the spacing and alignment issues of converting a font to a bitmapped texture; I've done it by hand many times and it isn't particularly easy! You can measure the width of each character automatically but in practice the results usually require tweaking beyond that. For instance, the letters 'b' and 'd' should both be centered about the 'o' part without regard to their 'stems'. I'd be interested if anybody knows how to solve these kinds of problems "on the fly".


Hi,
I don't understand exactly what you mean. Aren't these characters "centered" if you draw them with GDI's DrawText? To get the width I use GetCharABCWidths.
Are there difficulties which I didn't notice yet?

Share this post


Link to post
Share on other sites
Quote:
Original post by Zoomby
I don't understand exactly what you mean. Aren't these characters "centered" if you draw them with GDI's DrawText? To get the width I use GetCharABCWidths.
Are there difficulties which I didn't notice yet?

Well, I'm not trying to discourage you, just saying that -I- think it's hard to do this entire process manually, and you're trying to do it automatically!

My impression is that you're trying to make a bitmap with every character (and some symbols) which you can then use to compose text at render time. When you render a font you lose spacing, kerning, etc. information stored in the font file making it harder to reassemble your bitmap back into text, unless of course you're using a fixed width font.

Or perhaps I am mistaken and you're simply trying to pre-render certain phrases that you know you'll be needing; in that case the GDI function should take care of all that.

Either way, I'd love to see some screen shots if you get it working properly -- I've spent a lot of time on custom fonts in the past and I'm always interested to see how people do it.

Share this post


Link to post
Share on other sites
Quote:

My impression is that you're trying to make a bitmap with every character (and some symbols) which you can then use to compose text at render time. When you render a font you lose spacing, kerning, etc. information stored in the font file making it harder to reassemble your bitmap back into text, unless of course you're using a fixed width font.


When you render the text into the bitmap, you can store all of this information (spacing, kerning, character sizes, etc.) in an associated data structure. All of this is available via the various Win32 functions that return text metrics. After that it's a simple matter to position and texture quads with the font texture. There are a few programs out there that can do all of this work for you in advance and store all the pertinent data in a file for later use (one of which is my own project, glFont, among many others).

Share this post


Link to post
Share on other sites
Hi MasterWorks,

your right. I didn't think about kerning.
I guess I'll not implement these advanced techniques. At least not in the first step.

Technically, I think it's possibly. You can, for example, receive the kerning pairs with "GetKerningPairs", as strtok noted


Bye
Zoomby

Share this post


Link to post
Share on other sites

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