View Full Version : antialias and sprite masking

05-10-2007, 07:40 AM

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.

05-10-2007, 09:14 AM
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

05-10-2007, 09:22 AM
thanks for your reply k_szczech, sure that will work, but what if the sprite has more than one color (many solid colors) ??

05-10-2007, 01:15 PM
Either 'dilate' the colors on the letter egde (best), or 'erode' the alpha (easy).

05-10-2007, 01:42 PM
I did not understand the 'erode' alpha way...

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


05-10-2007, 02:19 PM
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...

05-10-2007, 03:50 PM
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.

05-11-2007, 10:11 AM
Fine you do the dilate by hand, but you still need to dilate :)

05-11-2007, 12:01 PM
thanks for your replies guys, I'll try to implement some 'dilate' algorithm similar to the one ZbuffeR said.