Recommended patch for SDL_ttf

Hello,

I have a very small change to SDL_ttf I wanted to suggest. Here’s a
little background on the problem I noticed:

When you call any of the TTF_Render*Blended functions, the result is the
rendered text on a 32-bit surface ready to be blitted. Blitting it as
it is will work great and look really nice. But if you resize that
surface, you’ll get some ugly artifacts that show up when blitting over
anything but black backgrounds. The reason is that the surfaces are
initially filled with black pixels with 0 alpha. Then when the glyphs
are drawn in whatever color (say white), the pixels are only drawn
within the bounding box of the glyph, creating characters that look
something like this when alpha is ignored:

B B B B B B B B B B
B B B B B B B B B B
B B B B B B B B B B
B B W W W W W W B B
B B W W W W W W B B
B B W W W W W W B B
B B W W W W W W B B
B B W W W W W W B B
B B B B B B B B B B

…where the glyph is contained completely in the “white” box. The
problem with this is that if you resize that image with methods like
bilinear resampling, the white pixels are going to get averaged with
black ones, even though the black ones are all 0 alpha. The simplest
way to solve the resizing problem is to make all pixels the same color.
Then blitting behaves exactly the same way because color doesn’t matter
for 0-alpha pixels, and resizing looks better because there are no
"unseen" colors to blend with.

So the fix in the patch is simply to add an SDL_FillRect() to the two
*Blended() functions to initialize all pixels on the surface to the
chosen foreground color with 0 alpha, rather than black with 0 alpla.
The fix makes fonts drawn with OpenGL textures look much nicer when
they’re stretched and skewed.

Sorry for the overly wordy explanation, but I guess it’s better to say
way too much at the beginning, rather than receive 10 “what are you
talking about?” e-mails :slight_smile:

Ryan

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed…
Name: ttf_color.patch
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20041224/5c2c1cd5/attachment.asc