DirectFont - Part
One
This tutorial is the first part in a two part
series on how to use DirectFont, a utility created by myself, and
available on the Downloads
page. DirectFont is broken into two distinct processes...creating
the font collections and then using them in your DirectX
application. This tutorial will cover the first half of
DirectFont...Font Collections and Definitions.
Contents
Setup
There are a couple things that need to be set
up on your computer in order to start using DirectFont.
- DirectX 7.0a. Simple...this is designed to
work with DirectX, so you need to have it installed.
- You need some font bitmaps. DirectFont works only off of
bitmaps that you supply. It does not use True Type fonts,
or any other kind of fonts that might be on your system.
What you want to look for is bitmaps that have characters
in them. If you just want some to try out, open up
MS-Paint, and draw the characters in a picture and then
save that as a bitmap and use that. However, if you go on
the web, there are lots of free graphics that will do the
job. Here's a site with some good links to free
alphabet graphics.
Back
To Top
DirectFont
Basics
- Now a little bit of terminology for you (from my point of
view)...When you are working with the DirectFont
executable, a definition refers to the actual BMP and the
RECTs that make up each character. For instance, you
could have 5 different definitions, one for each color of
text that you would like to use in your app. Now these 5
definitions are stored in one collection. Typically, you
would have one collection for each game you have, but
this is up to you. Maybe you want to classify you're
collections by size, or by look, or however else.
DirectFont makes sure, though, that each definition has a
unique name within it's collection, so they can be
identified later.
- You can start up DirectFont by double clicking the
DirectFont.exe icon. When you first start up DirectFont,
it has already created an untitled font collection for
you. On the left, you will see a treeview containing all
the font definitions in this particular collection (since
this is a new collection there are no definitions). The
right hand side of the screen will be where you do all
you're work.
- The File menu allows you to manipulate
collection level operations. You can close, save, open,
or create font collections from here.
- The Collection menu allows to manipulate
definition level operations. You can add font definitions
or remove them, to or from the current collection.
- The View and Window
menus allow you to control what is visible on the screen.
- The Help menu displays help for the
program.
Back
To Top
Font
Definitions
- Click Collection->Add Font Definition
(or press Ctrl+A). A dialogue box will
appear asking you how to create the new definition.
- There are two options here: You can either import a
existing definition that was exported in another
DirectFont session (the Binary option), or you can create
a brand new definition by using the Bitmap option. We
will create a new one, so select the Bitmap option.
- The dialogue expands for you to enter more options.
Choose and type the definition name, and use the Browse
button to select the actual BMP file to use. When this is
done click Create.
- You should now see three windows opened for you in the
right hand side of the screen. These windows contain all
the information about the definition you've just created.
You will also see three entries (corresponding to the
three windows) on the left hand treeview for easier
navagation. Select the Font Definition
node for your new defintion.
- A window displaying your bitmap comes up. Here is where
you actually define what RECTs make up each character in
the BMP.
- Simply press a key on your keyboard, and you should see
one of the labels reflect that key. There should also be
rectangle visible in the center of the BMP. This
rectangle is your definition. You can move this around,
expand it, shrink it, and adjust it until it fits
whatever character you've pressed.
- For example, if you press the letter 'A', move the
rectangle around until it covers the 'A' character on
your bitmap. When later on you use this definition in
your DirectX app, when you want to draw the letter 'A' to
screen, DirectFont goes back and looks at what area
you've defined as 'A', and blits this to the screen.
- Notice that you can only resize the rectangles
horizontally. This was done on purpose. Because you want
words to print in a straight line and line up (most of
the time), all characters must be the same height. The
height for this particular definition is controlled by
height toggle at the bottom of the window. If you change
this, though, it will change it for all the characters in
this definition, so try not to touch this too much (or
else go back and double check you're previous RECTs for
this definition).
- This is also the screen where you set the transparency.
Click the Transparency button, and the
cursor will change into an eyedropper. Line up the
cross-hairs with the color you want to be transparent
when DirectFont blits this definition to the screen.
- When you are done defining all you're rectangles and
transparency, click Update. This saves
the changes you've made to the internal data structure.
Back
To Top
Font Binaries
- Click on the Font Binary node in the
treeview for the newly created font definition. This
brings up the font binary screen.
- On this screen you will see the actual bytes (and ASCII
representation) of the definition you've created. You are
only allowed to view the data, not modify here.
- On the bottom you will see a Save
button. This allows you to save the binary representation
to be later imported into another DirectFont session.
This way if you are splitting up your collections by
project, you could use the same font definition (let's
say its the font you use for your title screen) in both
projects by exporting the first one, and then importing
it into the new collection (which is done by specifying
Create From Existing Binary on the Add New Definition
screen).
- Note, however, that you are not allowed to change the
name of the imported font definition (unless you HexEdit
the binary (which is not hard to do)), so when you first
create choose the name carefully.
Back
To Top
Font Test
- Click on the Font Test node in the
treeview for the newly created font definition. This
brings up the font testing screen.
- On this screen you will be able to test out the most
currently saved version of your font definition. This
means that only once you click the Update button on
the font definition screen will you see the proper
characters.
- When you first open the screen it will be divided into
two halves. The top half represents the testing area where
you see your font in action. The bottom half is the options,
where you set what the text says, and how you want to show
it.
- The top half is pretty self explanatory. It will display the
current characters according to the options selected on the
bottom half. If you defined more characters than be displayed
at the current width, the characters will move to the next
line. If you defined more lines than can be displayed at the
current height, no more characters will be blitted.
- There are a couple of options for the bottom half:
- Displayed Text: This allows you to choose what text
you want to display in the top half. You can choose from
some predefined ones (no, I'm not an egocentric maniac), or
define your own.
- Transparency: This determines whether it will use
transparency or not when it blits the characters to the
screen. This is pretty much what the DirectFontDLL does
for you, so you have a pretty good idea what you're final
product is going to look at.
- Zoom: This determines the zoom level of your font.
It can be adjusted from 50% - 200%. Again, this is the
same that you'll see using the DirectFont object (however
the zooming only works in the DLL with Blt, not BltFast).
- Background Color: This will fill the display section
with the color that you pick from the color popup. You can
use this to give you a good idea of what type of background
would be best for the font (i.e. bright, dark, dim, contrast,
etc.).
Back
To Top
Removing Definitions
- To remove a definition from the collection, you use Colleciton->Remove
Font Definition (or Ctrl+R).
- On this form, you place a checkmark beside any font
definition that you would like removed from the
collection and press Remove.
- There is no undo, so make sure that you've either saved
your work (and can revert back that way) or that you
really want to remove this definition.
Back
To Top
Finishing Touches
- So you're done now...you know the basics of using
DirectFont.
- When you are done, save you're work into a font
collection file, as we will need one for the second part
of this tutorial, the DirectFont DLL.
Back
To Top
Tips and Tricks
- When you make you're alphabet, always define the space
character (" "). Otherwise if you don't,
sentences will have all of their words run together, and
it'll be very hard to read.
- If you are going to use transparency, make sure to define
your transparent color (wow, I am the master of obvious
statements...). No, seriously, if you leave it at its default
of Black, and your bitmap has no Black in it, then it won't
work as you're expecting...
- Even if the alphabet set you got is only in one case
(uppercase or lowercase), make sure you define the
characters for both cases (so 'g' and 'G' define the same
section of the bitmap). This way you don't have to worry
about cases in your DirectX app.
Back
To Top
Please feel free to
contact me with any comments or questions about this tutorial or
the tools used.
Back
To Tutorials
Previous Part -
[1 2] - Next Part