[SOLVED] [MDX] TTF font temporary registration

Started by
2 comments, last by laucian 16 years, 8 months ago
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]
Advertisement
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.
-Mike
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.
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. :)

This topic is closed to new replies.

Advertisement