[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] SDL vs. Pygame: Alpha Differences



Pete Shinners wrote:
On Sat, 2006-12-23 at 12:10 -0800, Kamilche wrote:
In the SDL documentation, it says under 'SDL_SetAlpha':

"When blitting RGBA->RGBA with SDL_SRCALPHA: The source is alpha-blended with the destination using the source alpha channel. The alpha channel in the destination surface is left untouched. SDL_SRCCOLORKEY is ignored."

However, in Pygame, the alpha channel IS overwritten. Is there any technique to overcome this, to make it match what is written in the SDL documentation? Or is it a bug in SDL?

Yes, SDL has a special blitter for blending alpha to alpha. You can work around this by disabling the SRC_ALPHA flag on the source. then it will work the same as SDL.





I tried disabling the SRC_ALPHA on the source of a picture using two methods, and both of them still modified the alpha map of the original picture. Maybe you can tell me what I'm doing wrong?

# Sample program - 'full.png' should be a full color pic
# with an alpha channel.



import pygame

def main():
    pygame.init()
    nightcolor = (0, 0, 0, 64)
    bg = pygame.display.set_mode((800, 600), pygame.SRCALPHA, 32)
    bg.fill((128, 128, 128, 255))
    pic = pygame.image.load('full.png').convert_alpha()


''' # This blitted a black picture on top night = pygame.Surface(pic.get_size(), 0, 32) night.fill(nightcolor) night.set_alpha(None) pic.blit(night, (0, 0)) '''

    # This blitted a nighttime overlay, but messed up
    # the alpha channel of the destination pic.
    night = pygame.Surface(pic.get_size(), 0, 24)
    night.fill(nightcolor[:3])
    night.set_alpha(nightcolor[3])
    pic.blit(night, (0, 0))


bg.blit(pic, (0, 0)) pygame.display.update()


main()