BFF Format

Codehead's Bitmap Font Generator

BFF File Format

CBFG native output for font files is Bitmap Font File (BFF) format.
 
The format supports 8, 24 and 32 bit fontmaps up to 4096x4096 pixels and specifies character width and positioning information.

The files start with a 20 byte header:

Offset Size (Bytes) Description
0 2 ID - 0xBF 0xF2 (BFF Version 2)
2 4 Font Image width
6 4 Font Image height
10 4 Cell width
14 4 Cell height
18 1 BPP - will be 8, 24 or 32
19 1 Base character offset - This is the ACSII value of the first character on the font map.
20 256 Character widths
276 Variable Image map data


Rendering Text using BFF fonts

To render a specific character from the font follow this example pseudocode:

Calculate the number of characters per row on the texture. (Integer value)

RowPitch = ImageWidth / CellWidth

Calculate the row and column of the glyph within the texture. (Integer values)

Row = ( CharASCIIValue - BaseCharOffset ) / RowPitch
Col = ( CharASCIIValue - BaseCharOffset ) - ( Row * RowPitch )

Calculate the UV dimensions for a cell. (Floating point values)

ColFactor = CellWidth  / ImageWidth
RowFactor = CellHeight / ImageHeight

Multiply the row and column values by the UV factors to obtain the UV coords of the top left of the character.

U = Col * ColFactor
V = Row * RowFactor

Add the UV factors to the UV coords to find the bottom right of the character.

U1 = U + ColFactor
V1 = V + ColFactor

Render the glyph using the cell height and width values as polygon dimensions, apply the texture using the calculated UVs.

Use the character's ASCII value as an index into the array of width values to determine the spacing required to place the next glyph.