TMTH Posted February 15, 2017 Share Posted February 15, 2017 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 Quote Link to comment Share on other sites More sharing options...
Nockawa Posted February 17, 2017 Share Posted February 17, 2017 Hello, Thanks for reporting, I've created this Trello Card. I'm really focused right now to revamp the positioning engine, that's why I don't fix the other things right away. But once I'm done with the current task, I'll work on them immediately. Quote Link to comment Share on other sites More sharing options...
Nockawa Posted February 22, 2017 Share Posted February 22, 2017 @TMTH so I should not set width = xadv; right? but just feed width with the width property from the file and discard xadv? Quote Link to comment Share on other sites More sharing options...
TMTH Posted February 23, 2017 Author Share Posted February 23, 2017 @Nockawa, Yes, width is the width of the character, but you can't discard xadv because it defines position increment when moving from one character to the another. And yes, that increment is not equal to character width. Example is here https://www.gamedev.net/topic/330742-quick-tutorial-variable-width-bitmap-fonts/ Quote Link to comment Share on other sites More sharing options...
Nockawa Posted February 23, 2017 Share Posted February 23, 2017 Ok, I apparently I didn't look my code closer enough, let's go again then! Quote Link to comment Share on other sites More sharing options...
Nockawa Posted February 23, 2017 Share Posted February 23, 2017 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 Quote Link to comment Share on other sites More sharing options...
TMTH Posted February 23, 2017 Author Share Posted February 23, 2017 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 Quote Link to comment Share on other sites More sharing options...
Nockawa Posted February 23, 2017 Share Posted February 23, 2017 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. Quote Link to comment Share on other sites More sharing options...
Nockawa Posted February 24, 2017 Share Posted February 24, 2017 Hello @TMTH I've made the changes, I've built a BMFont map with the Arial font and the text is now displayed correctly. There's a new preview build reflecting these changes. If you have feedback, they are welcomed! GameMonetize and jpdev 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.