Jump to content

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.


Link to comment
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

Link to comment
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...