Border around text with TTF_RenderText

In my program I’m using this to write text:

SDL_Color clrWhite = { 255,255,255, 0 };
SDL_Color clrBlack = { 0, 0, 0, 0 };

TTF_RenderText_Shaded(font, “Hello”, clrWhite, clrBlack);

Is it possible to have a black (for example) border around each letter?
Also, is it possible to set “transparent” as background color for the text?

To have transparent color as background I could simply use TTF_RenderText_Solid,
but using this function the text is not smooth.

There’s three render modes for SDL_ttf… solid, shaded, and blended. If you
want smooth text with a transparent background, just go with blended. It
comes out with a transparent background, and it’s still pretty fast.

As for the borders, I don’t know. I don’t think that functionality is built
in - you might have to write your own routines for that, if you really need
that.On 6/8/07, voidstar wrote:

In my program I’m using this to write text:

SDL_Color clrWhite = { 255,255,255, 0 };
SDL_Color clrBlack = { 0, 0, 0, 0 };

TTF_RenderText_Shaded(font, “Hello”, clrWhite, clrBlack);

Is it possible to have a black (for example) border around each letter?
Also, is it possible to set “transparent” as background color for the
text?

To have transparent color as background I could simply use
TTF_RenderText_Solid,
but using this function the text is not smooth.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


“If you see somebody who you don’t know getting into a crop duster that
doesn’t belong to you, report them.” – President George W. Bush

“James Buchwald” wrote:

As for the borders, I don’t know. I don’t think that functionality is
built in - you might have to write your own routines for that, if you
really need that.

and it’s not trivial. i think you have to use freetype directly and
paint the outlines coming out of it with your own “colour brush”. i
once googled around alot, but could’nt find a free library, that was
able to render “nice” outlined fonts. some just do a simple edge
detection algorithm, but this really looks ugly.

best regards …
clemens

In order to get a simple border around each letter you have to draw your text
to a surface, and do a masked blit of that surface 9 times with the last one
being the center position.

In other words, blit border color to destination surface position x-1,y-1 then
x,y-1 then x+1,y-1 then x-1,y then x+1,y then x-1,y+1 then x, y+1 then x+1, y+1
then you draw the color you want for your text itself at x,y. At least that’s
how it’s done with bitmap fonts…

Sam Crow wrote:

In other words, blit border color to destination surface position
x-1,y-1 then x,y-1 then x+1,y-1 then x-1,y then x+1,y then x-1,y+1
then x, y+1 then x+1, y+1 then you draw the color you want for your
text itself at x,y. At least that’s how it’s done with bitmap
fonts…

but keep in mind, that this works only for non anti-aliased glyphs.

clemens

In order to get a simple border around each letter you have to draw your text
to a surface, and do a masked blit of that surface 9 times with the last one
being the center position.

Ok, it’s not so fast but at least it works!
Thanks!