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

[pygame] Fading antialiased fonts...



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.

Platform is Win2k, recent pygame from the install on pygame.org.

Here's a tiny test harness to show the problem, with three different
methods. Replace kitchener with whatever fonts you have lying around.  Just
click to see the behavior.

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.  Linux doesn't fade either.

----- cut here -----
import pygame, pygame.font
from pygame.constants import *

pygame.init()

screen = pygame.display.set_mode((400,400))
pygame.mouse.set_visible(1)

game_done = 0
messagetimer = 30

medfont = pygame.font.Font("fonts/kitchen.ttf", 18)

raw_msg_img = medfont.render("Hello there.", 0, (255,255,0))

while game_done == 0:
    screen.fill((0,0,0))
    event = pygame.event.poll()

    if event.type == KEYDOWN:
        if event.key == K_ESCAPE:
            game_done = 1

    elif event.type == MOUSEBUTTONDOWN:
        messagetimer = 255

    if messagetimer > 0:
        messagetimer -= 1
        msg_img = raw_msg_img.convert_alpha(screen)
        msg_img.set_alpha(messagetimer)
        x,y = (400 - msg_img.get_rect()[2])/2, 100
        screen.blit(msg_img, (x,y))

        msg_img = raw_msg_img.convert(screen)
        msg_img.set_alpha(messagetimer)
        x,y = (400 - msg_img.get_rect()[2])/2, 200
        screen.blit(msg_img, (x,y))

        raw_msg_img.set_alpha(messagetimer)
        x,y = (400 - raw_msg_img.get_rect()[2])/2, 300
        screen.blit(raw_msg_img, (x,y))
        raw_msg_img.set_alpha()

    pygame.display.flip()


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