Jump to content
  • Advertisement
Sign in to follow this  
simotix

Basic Bitmap Font Render

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

While I have made a topic like this in the past, this is from start to finish the most basic approach to bitmap font render. I am hoping someone can see what I am doing wrong here.

Bug #1: UV's
Since I store my characters every 128 pixels, it is very easy to obtain the bitmap X/Y values for each character. However, I am not sure how far to advance the UV's to properly draw them. I tried basically doing something like Promit posted for AngelCode bitmap font render, however, since I am not sure how they generate their values, I may be wrong here. You can see in the two images below that I am calculating my UV's wrong. This is not a "half-texel" issue, I am using DX11.

My question to Bug#2, how can I correctly advance my UV's? There is nothing wrong with the way I find the bitmap X/Y, only how I move them for rendering.

Bug #2: Letter placement
I am not sure how to correct move my characters or even correctly get the distance. Currently I just do "A +B + C". This map seem correct, however, if you look at the Arial image below, the "j" looks out of place inbetween the "n" and "f". There is also what appears to be issues with "b" and "y" for Arial, along with some issues for Times New Roman.

My question to Bug #2, how can I properly advance my characters?

It is worth noting that I am not interested in using any external libraries (such as FreeType), or any "hacks" to do this. I want to see this done correctly using the windows api. Doing either one of these is not up for discussion, if I wanted to use them I could have been done with this a long time ago.

Share this post


Link to post
Share on other sites
Advertisement
I don't really know the answer, but I can provide some insights:

Regarding your issue with pt and px, the size of the font on screen, if specified in pt, will depend on the dpi (dots per inch) setting you've selected for your document (or font renderer).

The size of a font usually represents the distance between the top of the lowercase letter "l" and the bottom of the lowercase letter "j" -- this is assuming you're using a "standard" font...

1 pt is a fixed measurement that is equal to 1/72 inch.

So if your document is set to 72 dpi, 1 pt = 1 pixel. If not, you'll get different font sizes between pt and px measurements.

Anyway, I'm not very familiar with C#, but SetMapMode(dc,MM_TEXT) in C++ does set 1 logical unit = 1 pixel on screen (which is the rough equivalent of setting a document to 72dpi in GIMP) -- what are you using in C# to do the equivalent of SetMapMode?

There may also be a setting for "font kerning" -- font kerning "pushes the characters closer together" whenever possible, so that, for example, if I write "pj," the "tail" of the "j" goes slightly under the p. This will probably cause some issues with the values you get from GetCharABCWidths, because it always depends on the character directly before the current character.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!