TMTH

Wrong character width with BitmapFontTexture

Recommended Posts

Character width calculation is wrong for not mono-spaced fonts. Error is here (BMFontLoaderTxt._buildCharInfo):

if (xadv) {
   width = xadv;
}

Character width is not always equal to xadv. Try to export Arial from BMFont and look to number characters  (48-57)

When rendering, wrong part of texture is taken for character.

@Nockawa

Share this post


Link to post
Share on other sites

I just recheck my code, thing is: I don't need to compute the position of the next char, right? I can just use the x and y position for this, right? I mean they are absolute values, right? If that's so, then I don't need xadvance

Share this post


Link to post
Share on other sites

I'm not sure that I understand your question.

There are two kinds of positions - position of glyph in the source texture, and position of glyph in the target texture (or on screen). rectangle(x, y, x + width, y + height ) gives you rectangle in source texture, in absolute, not normalized coordinates - the glyph, that has to be rendered.  On the other side, xoffset, yoffset, xadvance gives you directions on how to render that glyph in target. You need all of them  - xoffset and yoffset to render current glyph, and xadvance to find base position for the next glyph.

They've got a picture here http://www.angelcode.com/products/bmfont/doc/render_text.html

Share this post


Link to post
Share on other sites

Ok, now I'm reading the doc (RTFM rules...) I understand that it's actually way more complicated than what I did. But I did dead simple, it's not that complicate in absolute, I would even said that it makes more sense to me, the guys did that to pack as tight as possible the chars but still storing values to place them correctly during rendering! (which is btw something I have trouble with when using font converted from HTML because I don't have all these informations).

So it's great, now I know what to do and how to improve the rendering thanks to your information, it shouldn't be that hard to code, it's 4 additional properties to store and use.

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


  • Recently Browsing   0 members

    No registered users viewing this page.