Skip to content
pmprog edited this page Aug 29, 2012 · 4 revisions

This tutorial will guide you through loading up fonts and writing text out to the screen

Table of Contents

Preparing your font

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

Adding borders

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.

Rendering text

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

Tidying up

Once you are finished with a font, you should release it with a call to spFontDelete