Game Development Reference
In-Depth Information
Once a font is provided, we use it to construct a SpriteFont object which has facilities for
drawing strings and calculating the extents for text using the SpriteFont's font using the
function MeasureString. Another useful function is GetLineSpacing, it allows us to know
how much space the font requires vertically, it's useful when displaying rows of text.
A SpriteFont is used in conjunction with a SpriteBatch, when we wish to render a string of
text onto the screen, we need to provide the sprite batch that will hold the sprites for each
of the font's glyphs.
std::unique_ptr<SpriteBatch> spriteBatch(new SpriteBatch(deviceContext));
std::unique_ptr<SpriteFont> spriteFont(new SpriteFont(device, L"font.spritefont"));
spriteBatch->Begin();
spriteFont->DrawString(spriteBatch.get(), L"Hello, world!", XMFLOAT2(x, y));
spriteBatch->End();
TheDirectXtoolkitiscontinuallybeingdevelopedandhassupportforrenderinggeometry,
including 3D models. DirectXTK supports all the modern Microsoft® platforms.
You can read more about it at: directxtk.codeplex.com
Search WWH ::




Custom Search