FontTextureProcessor Class

Provides methods to convert a specially marked 2D bitmap into SpriteFontContent.

Namespace: Microsoft.Xna.Framework.Content.Pipeline.Processors
Assembly: Microsoft.Xna.Framework.Content.Pipeline (in microsoft.xna.framework.content.pipeline.dll)


public class FontTextureProcessor : ContentProcessor<Texture2DContent, SpriteFontContent>


The FontTextureProcessor class transforms a specially formatted bitmap-font texture into a SpriteFontContent object that can be loaded at run time as a standard SpriteFont object.

You can create a bitmap-font texture in the appropriate format using almost any raster drawing program. Place all the characters of the font in order on the bitmap as follows:

Each character should be arranged on the bitmap in a grid ordered from upper left to lower right. Monochrome characters should use white for solid areas and black for transparent areas. To include multicolored characters, add an alpha channel to the bitmap and use that to control which parts of the character are solid. Fill the spaces between each character and around the edges of the grid with a specific magenta color having the value Red:255 Green:0 Blue:255 Alpha:255. The processor packs the characters together as tightly as possible, eliminating any wasted space in the original grid.

The following figure shows an example of this kind of font texture.


The default behavior of FontTextureProcessor is to expect the first character at the upper left corner of the grid to be a space character (ASCII and Unicode code 32), and the one beside it to be an exclamation point (ASCII and Unicode code 33), and the succeeding characters to appear in Unicode order for all the characters that the font contains.

You can support a different range and order of characters by writing a custom processor that extends FontTextureProcessor by overriding the GetCharacterForIndex method. For example, the code below creates a processor class that you could use to load a bitmap font texture containing the numeric digits from 1 to 9:

public class MyFontTextureProcessor : FontTextureProcessor
   protected override char GetCharacterForIndex( int index )
      return (char)('1' + index);

Be sure to include the [ContentProcessor] attribute before the class declaration, as shown in this example.

See Also


FontTextureProcessor Members
Microsoft.Xna.Framework.Content.Pipeline.Processors Namespace


Windows XP SP2, Windows Vista