BMFont and how to interpret the .fnt file

From:http://www.gamedev.net/topic/284560-bmfont-and-how-to-interpret-the-fnt-file/

Yes, this is the right place for your question.


I've never gotten around to writing any tutorial or sample for using the font file. I should probably do that as it would make the tool more valuable.

Here's a short description of each attribute in the .fnt file.

lineHeight: is how much to move the cursor when going to the next line.

base: this is the offset from the top of line, to where the base of each character is.

scaleW and scaleH: This is the size of the texture. 

pages: gives how many textures that are used for the font.

id: is the character number in the ASCII table.

x, y, width, and height: give the position and size of the character image in the texture.

xoffset and yoffset: hold the offset with which to offset the cursor position when drawing the character image. Note, these shouldn't actually change the cursor position.

xadvance: is how much the cursor position should be moved after each character.

page: gives the texture where the character image is found.

Here's some pseudo code for rendering a character:

  // Compute the source rect
  Rect src;
  src.left   = x;
  src.top    = y;
  src.right  = x + width;
  src.bottom = y + height;

  // Compute the destination rect
  Rect dst;
  dst.left   = cursor.x + xoffset;
  dst.top    = cursor.y + yoffset;
  dst.right  = dst.left + width;
  dst.bottom = dst.top + height;

  // Draw the image from the right texture
  DrawRect(page, src, dst);

  // Update the position
  cursos.x += xadvance;


I hope that explains it.

I'll look into the bug. Thanks for letting me know.

Regards,
Andreas

[edit] fixed the pseudo code as Sly pointed out [/edit]

[Edited by - WitchLord on November 25, 2004 8:00:15 AM]  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值