Angelcode Values

Started by
6 comments, last by WitchLord 13 years, 3 months ago
I was interested in knowing how AngelCode generates their values, for the life of me I can not understand how these values are determined. Does anyone have any idea? I understand the "id, x, y, id" values, however, how does it generated the "width, height, xoffset, yoffset, xadvance" values?

For example, for a size 24 Times New Roman, here is the values it has.

char id=106 x=26 y=0 width=6 height=19 xoffset=-2 yoffset=3 xadvance=6 page=0 chnl=15
Advertisement
I assume you refer to BMFont. AngelCode is just the name of my site.

x, y = position in the texture for the character glyph
width, height = size of the character glyph in the texture
xoffset, yoffset = how the current position should be offset when drawing the glyph on the screen
xadvance = how much the position should be moved after drawing the glyph

The width and height is generated by drawing the character glyph to a bitmap and then determining then cropping of the parts that aren't touched by the actual glyph.
The xoffset, and xadvance are obtained through the characteristics of the glyph from the font itself (commonly known as the abc widths)
The yoffset is just the how much that was cropped off from the glyph when generating the texture

BMFont uses GDI from the Windows API to obtain the information from the font.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game


I assume you refer to BMFont. AngelCode is just the name of my site.


Sorry about that, yes I do. I for some reason put though ... I can't seem to name it now though.


The xoffset, and xadvance are obtained through the characteristics of the glyph from the font itself (commonly known as the abc widths)


I had been looking into using ABC Widths for this, however, I am not sure by how to calculate "xoffet" and "xadance". For "offsetX" I was just using the "A" value and for "xadvance" I was doing "A + B + C". Is this the correct way to calculate this?
Basically yes.

For most fonts you'll also need to take the kerning pairs to determine if there is a special adjustment that should be done between the two characters that you're drawing at the moment.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game


Basically yes.

For most fonts you'll also need to take the kerning pairs to determine if there is a special adjustment that should be done between the two characters that you're drawing at the moment.


Ah, thanks for the help. The xAdvance seemed typical, but the xoffset seem kind of trying, I had to always adjust it to a negative "A" value for my letters to "look right". I noticed you do not use kerning pairs in your font information though (or at least from what I saw), how do you get around needing that?

Also, how is the width of the character calculated? I thought it was just the B width plus an always positive "C" value.
If I remember correctly the character width is the B value. However in BMFont I use GetGlyphOutline to get the actual bitmap of the glyph, and then I determine the width from the bitmap instead.I export the kerning pairs for the font too. The kerning pairs can only be applied when drawing the actual text as the adjustment depend on the characters that are neighbouring each other. For example, the kerning pair for the letters A and T is usually a negative value to make the characters display a bit closer together, while the kerning pair for the letters A and M is usually a positive value.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game


If I remember correctly the character width is the B value. However in BMFont I use GetGlyphOutline to get the actual bitmap of the glyph, and then I determine the width from the bitmap instead.


So you use the "gmBlackBoxX" value of GLYPHMETRICS? Why do you use that over the B value?


I export the kerning pairs for the font too. The kerning pairs can only be applied when drawing the actual text as the adjustment depend on the characters that are neighbouring each other. For example, the kerning pair for the letters A and T is usually a negative value to make the characters display a bit closer together, while the kerning pair for the letters A and M is usually a positive value.


I have never seen an example that using the kerning information from BMFont, do you happen to know of one? I thought that you only used ABC widths.
I use GetGlyphOutline because it gives me more information that I need. However, it only works for TrueType fonts. For raster fonts I still use GetCharABCWidths.

Using the GetGlyphOutline you get the values like this:


m_width = gm.gmBlackBoxX;
m_height = gm.gmBlackBoxY;
m_xoffset = gm.gmptGlyphOrigin.x;
m_advance = gm.gmCellIncX;
m_yoffset = fontAscent - gm.gmptGlyphOrigin.y;


Almost all true type fonts have kerning pairs, the exception being monospaced fonts, like courier. You can draw the text without taking the kerning pairs into account, but you'll see some strange gaps between characters where the kerning pairs where ignored.

My sample code that shows how to render text with bitmap fonts uses kerning pairs. You can also have a look at the implementation of the CFont class I use to load bitmap fonts generated by BMFont.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement