This might be a basic question but googling isn't turning out anything useful:

How are we supposed to use TTF_SetFontOutline ? I know we're able to create an outline (and it looks alright) but since it's the same colour as the main font I don't see any practical usage for it.

I can't find any way to set the colour separately and rendering two font instances makes it very hard to line up.

So what is a typical usage case for it?


2 Answers 2


You can acheive what you want by drawing the text with an outline in one color, and then drawing it without outline on top of that, in another color.

Here's an example of white text with a black outline from the libsdl forum:

#define OUTLINE_SIZE 2

/* load font and its outline */ 
font = TTF_OpenFont(font_path, font_size); 
font_outline = TTF_OpenFont(font_path, font_size); 
TTF_SetFontOutline(font_outline, OUTLINE_SIZE); 

/* render text and text outline */ 
SDL_Color white = {0xFF, 0xFF, 0xFF}; 
SDL_Color black = {0x00, 0x00, 0x00}; 
SDL_Surface *bg_surface = TTF_RenderText_Blended(font_outline, text, black); 
SDL_Surface *fg_surface = TTF_RenderText_Blended(font, text, white); 
SDL_Rect rect = {OUTLINE_SIZE, OUTLINE_SIZE, fg_surface->w, fg_surface->h}; 

/* blit text onto its outline */ 
SDL_SetSurfaceBlendMode(fg_surface, SDL_BLENDMODE_BLEND); 
SDL_BlitSurface(fg_surface, NULL, bg_surface, &rect); 

/* we now have RGBA white text with black outline in bg_surface */ 

The colour is set to be the same as the font, so it can't be used as you'd like it to be.

I'd suggest having a look at bitmap fonts, there's a tutorial here.

Alternatively, if you'd like to continue using SDL_TTF, you could look into generating a glyph atlas. I personally don't have much experience with this but it is explained in another question here.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .