[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Fading antialiased fonts...



Scott Russell wrote:
> When I try to fade antialiased ttf text, I get some strange results - either
> it a) doesn't fade, or b) I get some kind of blocky version of my text that
> does fade, depending on which method I attempt.  Some methods work fine with
> aa turned off.
> 
> I'm assuming this is related to per-pixel alpha, but that's just a guess.  I
> don't know much about ppa.

your guess is pretty much correct. SDL does not allow you to mix
"per-pixel" alpha and "surface" alpha. once the surface has the
per-pixel alpha, sdl will ignore the surface alpha.

sdl does work properly with colorkeys and source alphas, that is why the 
text fades properly for the images with no perpixel alpha.

your best solution is to create what SDL_ttf calls "blended" text.
this is text that uses a colorkey for transparancy, but the edges of the 
text are antialiased towards a specific color. this of course only works 
well when the background for the text is going to be a certain color.
here's a quick function to do it for you.

def blendedtext(font, text, color, bgcolor):
	img = font.render(text, 1, color, bgcolor)
	img.set_colorkey(bgcolor)
	return img

this will give you text with a smooth antialiased edge and will still 
allow the surface alpha to do the fading. it will also blit much quicker 
than the normal antialiased text, since perpixel alpha blits are 
relativelely slower. the only drawback is the text edge must "antialias"
to a specific color.


> In testing, CrashChaos also reported in IRC that on linux, this harness
> shows blue text when aa is on, yellow when off.  Yellow all the time in
> Win2k.

this is a bug with SDL_ttf 2.0 through 2.0.3. it's been fixed in the 
latest version of SDL_ttf, 2.0.4








____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org