This project has moved and is read-only. For the latest updates, please go here.

Adding .spritefont files

Dec 2, 2013 at 10:37 PM
How do you add .spritefont files so I can use them to draw text to the screen?
Dec 2, 2013 at 10:57 PM
Edited Dec 2, 2013 at 11:13 PM
The .spritefont file is like any other data file. You just need to have it deployed with your app, and use whatever relative path is needed to find it at runtime in your constructor.

For a Windows Store app or Windows phone project, you need to include it in your AppX package. You must add the file to your VC++ project, and mark it as "Content: Yes" for all configurations (this is done automatically for images and the like, but not for other data files).
Dec 3, 2013 at 11:03 AM
walbourn wrote:
The .spritefont file is like any other data file. You just need to have it deployed with your app, and use whatever relative path is needed to find it at runtime in your constructor.

For a Windows Store app or Windows phone project, you need to include it in your AppX package. You must add the file to your VC++ project, and mark it as "Content: Yes" for all configurations (this is done automatically for images and the like, but not for other data files).
I have tried to add tff files but it didnt work, where do you download .spriefont files or how do you convert tff to .spritefont? Sorry if its a stupid question.
Dec 3, 2013 at 6:50 PM
Edited Dec 3, 2013 at 6:52 PM
This is currently a manual process as there's not built-in VS content pipeline support for invoking the needed tool.

.spritefont files are generated by the MakeSpriteFont command-line tool that's part of DirectXTK. It is used to capture an installed TrueType font into a .spritefont file, which is essentially a .DDS texture with some extra meta-data for the glyph locations that is used by SpriteFont.
Dec 21, 2013 at 2:21 PM
Thanks for replying but where do I put the command: MakeSpriteFont.exe "Kooten" myfile.spritefont /FontSize:16 for example?

How do I use the tool?
Dec 21, 2013 at 9:02 PM
Have you looked at the wiki?
Dec 22, 2013 at 1:25 PM
Edited Dec 22, 2013 at 1:26 PM
Yep, if I try to use 'MakeSpriteFont.exe "Kooten" myfile.spritefont /FontSize:16' in the header file I get a red line saying: 'this declaration has no storage class or type specifier'. Basically I have no idea how to declare it properly as it's a tool.
Dec 22, 2013 at 9:13 PM
Edited Dec 22, 2013 at 9:20 PM
Ah. MakeSpriteFont is a command-line executable, not a language construct. Open a Command Prompt, type
MakeSpriteFont.exe "Kooten" myfile.spritefont /FontSize:16
Hit enter. The tool generates a file "myfile.spritefont" which you then use as a data file in your program (the Kooten.ttf installed TrueType font is not used by DirectXTK's SpriteFont class at all...)
Marked as answer by Yoshimiii on 12/23/2013 at 6:38 AM
Dec 23, 2013 at 2:09 PM
Edited Dec 23, 2013 at 2:51 PM
Ah, that makes sense, I should have read the wiki more carefully. Thanks so much.

Anyone else who might want to know this I had to go to the DirectXTK/MakeSpriteFont directory and run MakeSpriteFont.csproj.

I then did 'rebuild solution' and closed it and it generated a makespritefont.exe in the Debug/bin folder. Then I set the cmd directory to that location and did the MakeSpriteFont.exe command.

Also It wasn't Kooten, it was Kootenay. The name of the file is different to the file I had to type into the cmd.
Dec 23, 2013 at 6:55 PM
Edited Dec 23, 2013 at 7:07 PM
I'm sorry, I forgot a critical step before running MakeSpriteFont.exe. You need to change the current working directory to the location where you built the tool. For example, if you have DirectXTK in your VS projects folder:
cd "C:\Users\<your-user-name>\Visual Studio 2012\Projects\DirectXTK\MakeSpriteFont\bin\Release"
Note that the command-line tools in the DirectXTK package are only built by the DirectXTK_Desktop_201x solutions since they are Win32 desktop applications. You can also obtain them as a pre-built binary from the download page as "Other available downloads"

I strongly recommend getting some basic familiarity with console execution via the Command Prompt or perhaps Windows PowerShell. There are a huge number of extremely useful tools for developers that are used in this way. Just search for "command prompt tutorial" in your favorite search engine...
Marked as answer by walbourn on 12/23/2013 at 11:05 PM
Apr 18, 2014 at 6:40 PM
I can't seem to get MakeSpriteFont to work. I'm on Windows 8 and typed this in the comand line where I extracted the exe and I only seem to get a "Can't find font" message whatever I try:

C:\Program Files (x86)\MakeSpriteFont>MakeSpriteFont.exe "Arial", "C:\Users\A\Documents\Arial.spritefont /FontSize:18

Do I need to do anything to make it look in the right place? I know I have all the fonts I've been trying because I checked in Control Panel\Appearance and Personalisation\Fonts.
Apr 18, 2014 at 8:19 PM
Edited Apr 18, 2014 at 8:20 PM
Try
MakeSpriteFont.exe "Arial" "C:\Users\A\Documents\Arial.spritefont" /FontSize:18 
Apr 18, 2014 at 10:01 PM
Oh, duh! It was just because I added a comma? Now I feel stupid. Thanks for pointing that out.