TrueType font output

To the TTF setup functions>>

sge_tt_textout

Renders the given Latin-1/Unicode/UTF-8 string on surface with the given font.

SDL_Surface *Surface - The surface to render text to.
sge_TTFont *font - The font to render the text with.
const char *string or const Uint16 *uni - The Latin-1/Unicode/UTF-8 text string.
Sint16 x, Sint16 y - The leftmost point of the baseline for the text.
Uint32 fcolor or Uint8 fR, Uint8 fG, Uint8 fB - The color of the font.
Uint32 bcolor or Uint8 bR, Uint8 bG, Uint8 bB - The background color (see below).
int Alpha - Sets the transparency of the text (0-255).

You can use sge_TTF_AAOn(), sge_TTF_AAOff() and sge_TTF_AA_Alpha() to control how the text is rendered. If you use antialiasing, the background color must be set to the background color of the area where you will render the text. If the background has more than one color it might be better to use sge_TTF_AA_Alpha().
Does lock and update the surface. Does respect clipping.

Returns SDL_Rect: The size and position of the rendered text.


sge_tt_textoutf

Just as sge_tt_textout() but with the same syntax as printf().

Example

#include <iostream>
#include <string>
#include "SDL.h"
#include "sge.h"

using namespace std;

...

//Init font engine and exit on error
if(sge_TTF_Init()!=0){
cerr << "TT error: " << SDL_GetError() << endl;
exit(1);
}
//Open font and exit on error
sge_TTFont *font=sge_TTF_OpenFont("font.ttf", 25);
if(!font){
cerr << "TT error: " << SDL_GetError() << endl;
exit(1);
}
string text("Hello World!");

sge_tt_textoutf( screen, font, 10,100, 0,200,100, 0,0,0, SDL_ALPHA_OPAQUE, "Testing: %s", text.c_str() );

sge_TTF_CloseFont(font);


To the TTF input functions>>





Copyright © 1999-2003 Anders Lindström
Last updated 030803