This is a native Direct3D 11 implementation of a bitmap font renderer, similar to the SpriteFont type from XNA Game Studio, plus a command line tool (MakeSpriteFont) for building fonts into bitmap format. It is less fully featured than Direct2D and DirectWrite, but may be useful for those who want something simpler and lighter weight.
SpriteFont is particularly useful for the Windows phone 8 platform that lacks support for Direct2D and DirectWrite
For exception safety, it is recommended you make use of the C++ RAII pattern and use a std::unique_ptr or std::shared_ptr
The Draw method has several overloads with parameters controlling color, rotation, origin point, scaling, horizontal or vertical mirroring, and layer depth. These work the same way as the equivalent SpriteBatch::Draw parameters.
SpriteFont is particularly useful for the Windows phone 8 platform that lacks support for Direct2D and DirectWrite
Initialization
The SpriteFont class requires a SpriteBatch instance and a .spritefont bitmap file.std::unique_ptr<SpriteBatch> spriteBatch(new SpriteBatch(deviceContext)); std::unique_ptr<SpriteFont> spriteFont(new SpriteFont(device, L"myfile.spritefont"));
Simple drawing
spriteBatch->Begin();
spriteFont->DrawString(spriteBatch.get(), L"Hello, world!", XMFLOAT2(x, y));
spriteBatch->End();
Constructors
SpriteFont has three constructors:- Pass a filename string to read a binary file created by MakeSpriteFont
- Pass a buffer containing a MakeSpriteFont binary that was already loaded some other way
- Pass an array of Glyph structs if you prefer to entirely bypass MakeSpriteFont