Alpha channel - was Re: Truetype vs bitmapped fonts? Opinions?

vining at pacificcoast.net wrote:

Here’s the real best way to go, IMO, and an example of how I feel C++ and classes should be used. More on this sort of ranting
later, as if you haven’t heard enough!

Create a CFont object. When it initializes, have it choose a font, and a point size. This font’s constructor then renders letters using
SDL_ttf (or whatever) for each letter in the font that you’ll actually end up using (for easy use, always store your font
characters internally in some sort of useful format, like ASCII characters). Store 'em with alpha values, like Bill suggests, the
smart fellow that he is. Then, your code for rendering would be called something like:

myFont->printf(0,0,“Mord wuz here\n”);

which just goes through and blasts down the bitmaps. Then, if you need another font, allocate another CFont object. Best of both
worlds.

This is just what the SDL_bmf library does
(for bitmapped characters, not ttf), except the
part about alpha values. Can someone explain
(maybe in a private email) what is the purpose
of alpha channels, or point me at relevant
documentation? I gather it has to do with
transparency, but I’m really fuzzy beyond that.

TIA,

– Joe

Nichol

– Joe Knapka

This is just what the SDL_bmf library does
(for bitmapped characters, not ttf), except the
part about alpha values. Can someone explain
(maybe in a private email) what is the purpose
of alpha channels, or point me at relevant
documentation?

Alpha channels allow pixels to be blended together. For a good example,
try playing with a paint program like PhotoShop or GIMP. Set up two layers,
one with a picture, and another with text…

Then start fiddling with the transparency of the text layer… you’ll see
what happens when alpha values get changed :slight_smile: (the text fades in and out
of opacity)

I gather it has to do with
transparency, but I’m really fuzzy beyond that.

Exactly. Well, imagine unantialised text. (That is, text which is drawn
in just color or no-color… let’s say black and white, since it’s
simpler)

Take the letter O:###

Notice how it looks kind of stair-steppy? Jagged? Well, if you antialias,
using ‘in-between’ colors (ie, grey), it looks smoother:

+###+
+# #+
#+ +#

#+ +#
+# #+
+###+

(ok, my ASCII drawing sucks, but still… you get the picture, hopefully)

Ok, so say we had a font with black text that’s antialised to white (ie,
the in-between colors are grey). It’ll look great on a white background!

Now… the problem here is when you try to draw it on, say, a medium-blue
background. Now you have weird grey edges… it would’ve been better to
just not antialias it in the first place. <:^(

This is where the alpha channel comes in. Instead of saying “grey”,
we just say “black with 50% transparency”, for example.

Now, when we draw this black alpha-channel-enabled text on a white background,
the antialias pixels will be grey. It’ll look great!

And when we draw it on a medium-blue background, the antialiased pixels
will be dark blue. It’ll still look great!

In other words, alpha channels let you antialias your images without
being concerned as to what background they’ll be on…

I’m a bit distracted by Mad Max: Beyond Thunderdome on TV, so I’m sure this
isn’t the best explanation… but, there are no doubt tons of better
descriptions on graphics- and game-related websites and in books!

Take care!

-bill!