[slightly OT] Freetype2 and SDL_ttf

wrote

i’ve ne’er tried the 2.x releases. use the latest 1.x release.
follow the steps in the build instructions and you’ll can get a
freetype.lib quick and easy. (use the dosbox, luke!)

Ahh! A whole world of difference. :slight_smile: I used freetype 1.3.1
(it does have a VC++ project file so building it was a no-brainer).
I did manage to remember why I was looking into freetype2
in the first place… patent issues with 1.x that they (supposedly)
solved in freetype2 by using auto-hinter.

glad it worked. tough about the patent issues, but i guess if
freetype goes down there’s gonna be a lot of unhappy campers out
there :[

One question though… it looks like shaded rendering antialiases
against a color you feed to it. Any idea how to make it antialias
against any arbitrary bitmaps? Or maybe a more generic issue,
can it do alpha-blending? (transparent floating text… mmmm…
drools)

use the TTF_RenderX_Blended instead of TTF_RenderX_Smooth. this will
create a surface with an alpha channel that will do the correct
blending. once you have the rendered surface you can easily change
the overall transparancy with SDL_SetAlpha(). i’ve done some quick
tests with this and it does look good. probably worth enabling
SDL_RLEACCEL if you plan on using it a lot.

wrote

I tried using …_Blended functions. If I set the transparency/opacity
argument of SDL_SetAlpha( ) to anything other than 0, it displays a
nice, alpha-blended filled rectangle of the same color my text had.
That’s it. :frowning: Using zero produces normal, fully opaque, antialiased
text.

no you are correct here. after looking through SDL’s blitting,
it appears pixel alphas will override any surface alpha.
personally, i would prefer pixel alpha being combined with
surface alpha.

to workaround this problem here’s what you’ll need to do. render
the text as blended like you have now, but to get that onto the
destination transparently, you’ll have to do a little trickery.
grab a copy of the destination rectangle into a temporary surface.
now blit the text onto the temporary surface. set the alpha of the
temp surface to be the final amount of text transparancy and blit
that back onto the final destination.

it’s a bit roundabout, but it should work. sorry to lead you
astray with the alpha stuff. i guess i should have checked it
out more, but i remember the blended giving nice edges, and i
now know all the stuff i’ve seen with transparent text was using
a colorkey.

the other option is to pick a ‘best-fit’ background color and
use the smooth rendering, then set the colorkey and surface alpha
and you’ll get the results you want. (with a little colored halo
where you background doesn’t quite match your background color)

no you are correct here. after looking through SDL’s blitting,
it appears pixel alphas will override any surface alpha.
personally, i would prefer pixel alpha being combined with
surface alpha.

It was a design decision, but I don’t think it would break anything if
we changed it to combine the alphas. The problem is that it would
require a whole new blitter, and one that I wasn’t able to implement
efficiently. Basically an extra multiplication for each pixel would be
required, and I had my doubts whether it could ever be hardware
accelerated.

I could write a slow catch-all routine of course, but would that
be useful? I don’t like implementing things that can’t be done well.