Sign in to follow this  

[SOLVED] [MDX] TTF font temporary registration

This topic is 3771 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my game, I have no trouble rendering fonts already registered in the c:\windows\fonts directory. What I want to do is to load and display fonts which are stored in my game directory - so that they don't have to be installed in the windows directory. I'm using DXUT to render my entire GUI HUD loading fonts via Microsoft.Samples.DirectX.UtilityToolkit.Dialog.SetFont(ScoreString, "Babylon Industrial", 35, FontWeight.Bold); I have the file BABIND.ttf in my game directory, which doesn't load automatically, so I start my game, and the default font comes up (Arial?) However, if I double click on the font file, fontview.exe displays the font. If I then run my game again, the font is displayed correctly within the game. Closing fontview.exe and restarting the game results in my font not being displayed any longer. Is there any way to temporarily register the font for the duration of the app running? Or is there some other, better way to render fonts in game? A good bitmap font package for C#/MDX? [Edited by - laucian on August 14, 2007 11:01:58 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Anon Mike
I don't know how it's done in managed code but in native code what you do is call AddFontResourceEx with the FR_PRIVATE flag. This essentially registers the font with the system so you can use it like any other, but only for your process.
In addition, if it's useful to anyone, you can also use AddFontMemResourceEx in a similar way to use a font that's stored in memory somewhere. That lets you use resources or pack files or whatever you want.

Share this post


Link to post
Share on other sites
Thanks Mike & Steve. I was mentally preparing to write custom bitmapped font code.

After doing some searching based on your posts, I found PrivateFontCollection does the job in the same way as AddFontResourceEx with the FR_PRIVATE flag.


System.Drawing.Text.PrivateFontCollection _pfc = new PrivateFontCollection();
try
{
_pfc.AddFontFile("babind.ttf");
}
catch (System.IO.FileNotFoundException ex)
{
Common.Log.WriteError("File not found: " + ex.ToString());
}



Which solves all my ttf font worries. Thanks again. :)

Share this post


Link to post
Share on other sites

This topic is 3771 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this