Game Development Reference
In-Depth Information
Note
To quickly open the command prompt in your current folder, hold
Shift
while you
right-click and select
Open Command Prompt Here
.
This will output a file named
GameFont.font
, which we can include in our game as
we did with the images previously. Don't forget to set the
Content
property to
true
.
Drawing the font
Now let's get this text onto the screen. The steps here are pretty simple, just like our
sprite rendering before.
Inside the game we need to define a
SpriteFont
that will hold our font data and
work with
SpriteBatch
to render the text. Add this underneath the
SpriteBatch
definition:
std::shared_ptr<DirectX::SpriteFont>
_spriteFont;
Now we need to load this up using the constructor of
SpriteFont
. The best place
to do this would be after loading the sprites inside the
Game->Load()
function.
Microsoft::WRL::ComPtr<ID3D11Device>
d3d11Device;
m_d3dDevice.As(&d3d11Device);
_spriteFont =
std::make_shared<DirectX::SpriteFont>(
d3d11Device.Get(),
L"GameFont.font"
);
Here we need to get the
ID3D11Device
version of our graphics device, and we
only have the
ID3D11Device1
version. So, just as with our earlier conversion of the