Working with Fonts

From GMod Wiki

Revision as of 20:07, 16 October 2011 by Donkie (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The default font used in most functions won't serve for many of your uses. Often there will be a need to use a different one so that the text is possible to see for a player, or has the impact that you want it to. You can either use an existing font or import one into the game with surface.CreateFont. In this article is a list of the default fonts and images of what they look like in game.

Here is a list of the functions and methods that allow you to change fonts:

Preexisting fonts

What the fonts look like in game.

Below is a list of fonts that exist by default in Garry's Mod:

DebugFixed
DebugFixedSmall
DefaultFixedOutline
MenuItem
Default
TabLarge
DefaultBold
DefaultUnderline
DefaultSmall
DefaultSmallDropShadow
DefaultVerySmall
DefaultLarge
UiBold
MenuLarge
ConsoleText
Marlett
Trebuchet18
Trebuchet19
Trebuchet20
Trebuchet22
Trebuchet24
HUDNumber
HUDNumber1
HUDNumber2
HUDNumber3
HUDNumber4
HUDNumber5
HudHintTextLarge
HudHintTextSmall
CenterPrintText
HudSelectionText
DefaultFixed
DefaultFixedDropShadow
CloseCaption_Normal
CloseCaption_Bold
CloseCaption_BoldItalic
TitleFont
TitleFont2
ChatFont
TargetID
TargetIDSmall
HL2MPTypeDeath
BudgetLabel
Special fonts that you might also use.

Creating Fonts

Custom fonts should be defined in the hook GM:Initialize, using the surface.CreateFont function.

 
surface.CreateFont( "akbar", 48, 500, true, true, "MyFont" )
 

This will create a font called "MyFont". Custom fonts persist even if the game server (local or network) is reloaded, so if the font "MyFont" already exists then nothing will be created. However, you can call the console command gm_clearfonts to clear all of the known custom fonts. This is a developer console command and should never be called from a mod/gamemode. If you make a change to a surface.CreateFont function in a script while the game is running, you will need to run gm_clearfonts in order for the changes to your font(s) to show.

Using Fonts

To use a font, self made or otherwise, simply use the name of it in place of the 'font' argument, such as:

 
draw.SimpleText( "Hello!", "MyFont", 100, 100, color_white )
 

Notes

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox