antialias and sprite masking


I’m trying to draw masked sprites with antialias. For example, let say I have a texture which is letter A, it has two colors, white for the solid pixels (alpha=1.0), and magenta for the background (alpha=0.0), then I render this texture as a 2D texture quad using GL_LINEAR as filters (for antialias), and I use the Alpha Test to skip background pixels, the problem is that the antialiased parts is a mix of white and magenta scaled colors… how can I render this sprite (texture) with both masking and antialias ??, the antialias I want it to be mixed with the scene background not with the sprite’s mask color…

Thanks in advance.

It’s very simple actually. When you load an image from disk you process it to add alpha channel right? Simply fill your texture with white color during that process so there are no more magenta pixels. Only white+alpha=1.0 and white+alpha=0.0

thanks for your reply k_szczech, sure that will work, but what if the sprite has more than one color (many solid colors) ??

Either ‘dilate’ the colors on the letter egde (best), or ‘erode’ the alpha (easy).

I did not understand the ‘erode’ alpha way…

is there any other way without image processing (except for the background color conversion) ???..


Dilate : (see example with text)
Erode is simple the inverse operation.
Either you ‘enlarge’ the color channel, either you ‘shrink’ the alpha channel.

There is no other way.
You have to understand that both alpha and color channels are interpolated.
This is what you want, else there would be hard blocky edges around your letters.

If your are lazy, find the average color of your “sprite” and use that as background. Use Medium grey if you are really lazy…

There is no other way.
There is one and I’m using it - I paint images with alpha channel and save to PNG (it supports alpha cannels). I do all necessary color bleeding in Paint Shop Pro - my application just loads these images and oesn’t have to do anything with it - just display.

Fine you do the dilate by hand, but you still need to dilate :slight_smile:

thanks for your replies guys, I’ll try to implement some ‘dilate’ algorithm similar to the one ZbuffeR said.