Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a good way to render outlined fonts?

I'm writing a game in python with pygame and need to render text onto the screen.

I want to render this text in one colour with an outline, so that I don't have to worry about what sort of background the the text is being displayed over.

pygame.font doesn't seem to offer support for doing this sort of thing directly, and I'm wondering if anyone has any good solutions for achieving this?

like image 241
SpoonMeiser Avatar asked Jul 10 '09 13:07

SpoonMeiser


2 Answers

A quick and dirty way would be to render your text multiple times with the outline color, shifted by small amounts on a circle around the text position:

          1
       8  |  2
        \ | /
         \|/
     7----*----3
         /|\
        / | \ 
       6  |  4
          5

Edit: Doh you've been faster ! I wont delete my answer though, this ASCII art is just too good and deserves to live !

Edit 2: As OregonGhost mentioned, you may need more or fewer steps for the outline rendering, depending on your outline width.

like image 131
Luper Rouch Avatar answered Oct 07 '22 23:10

Luper Rouch


I can give you a quick and bad solution:

print the text 8 times, to surround it, plus one more time for the inner text, like this

UUU
UIU
UUU

U for outer color and I for the inner color.

like image 38
Nick Dandoulakis Avatar answered Oct 08 '22 00:10

Nick Dandoulakis