-
Notifications
You must be signed in to change notification settings - Fork 9
Tutorial: font
This tutorial will guide you through loading up fonts and writing text out to the screen
Firstly you have to define your variable
spFontPointer MyFont;
You can then set this variable using the spFontLoad call, passing in the path of the TTF font file, and the font's text size.
The final step requires you to add the range of characters available from the font drawing routines
spFontAdd( MyFont, SP_FONT_GROUP_ASCII, spGetRGB( 0, 0, 0 ) );
The above line will add all ASCII available characters in black
Some times bordering the text makes it easier to read, so this can be done by the spFontAddBorder call, which takes the font pointer and colour of the border to be used.
There are three functions: spFontDraw, spFontDrawRight, spFontDrawMiddle. All three function in the same manner, except for the X position. In the normal spFontDraw, the text is drawn starting at the X position, spFontDrawMiddle is centred around the X position, and with spFontDrawRight, the text ends at the X position.
If you need to make some manual adjustments based on a strings drawing size, you can use the spFontWidth call to retrieve the width required to draw the passed string
Once you are finished with a font, you should release it with a call to spFontDelete