PS2 Linux Programming

 

Rendering Text with In-Built SPS2 Functions

 

 

Introduction

 

The previous tutorial “Rendering Text” demonstrated how to draw text to the screen using a custom developed bitmap font class. From SPS2 version 0.4.0, functions for rendering text to the screen have been made available and they are demonstrated in this tutorial.

 

 

SPS2 Text Rendering Functions

 

The function prototype for the SPS2 printing functions is:

 

int sps2UPrintf(sps2UFontStruct * pFont, const char * format, …);

 

pFont is set to NULL to use the default font or point to a font created by x_font_tosps2_u_font, which is a utility provided with SPS2 to create compatible font files (see the SPS2 documentations for more details). sps2UPrintf() queues a string for printing with the actual rendering being done when sps2UPintfRender() is called. The z depth of the string is placed according to the Z value specified by sps2UPrinfSetZ() with the (X, Y) values being set relative to the previous call to sps2UPrintf() unless they are overridden by a special token (see below) placed in the print string or by a call to sps2UPintfSetPos().

 

Two special tokens can be embedded into the print string:

\377RRGGBB – The characters that follow (on that line only) will be displayed in the colour specified by the hex value RRGGBB.

\366(x,y) – The characters that follow will be displayed at coordinates (x,y) relative to the top of the window defined by sps2UPrintfSetWindow().

 

If not otherwise specified, the display window will be set to fill up the whole screen (when sps2UScreenInit() is called) with a default Z value of 128 and a default colour of bright white.

 

 

Example Code

 

The example code illustrated rendering text to the screen with the in-built SPS2 functions. The render loop is reproduced below for clarity.

 

while(true)

    {

      // Clear the screen

      sps2UScreenClear(0x0, 0x0, 0x0);

 

      // Render some text

      sps2UPrintf(0, "\377808080\376(500,20)Frame = %d", iFrame++);

      sps2UPrintf(0, "\377808080\376(500,40)Time = %.2f", iFrame/60.0f);

     

      sps2UPrintf(0, "\377800000\376(100,200)0123456789");

      sps2UPrintf(0, "\377008000\376(100,250)ABCDEFGHIJKLMNOPQRSTUVWXYZ");

      sps2UPrintf(0, "\377000080\376(100,300)abcdefghijklmnopqrstuvwxyz");

 

      sps2UPrintfRender();

      // Display the buffer we were just drawing to

      sps2UScreenSwap();

    }

 

The colour and position of the text strings are set in each call fo sps2UPrintf().

 

 

Conclusion

 

In this tutorial the use of the in-built SPS2 font rendering functions have been used to rendered text to the screen.

 

 

Dr Henry S Fortuna

University of Abertay Dundee

h.s.fortuna@abertay.ac.uk