[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] [BUG] blend modes and rotated images not respecting color key or maybe alpha.
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] [BUG] blend modes and rotated images not respecting color key or maybe alpha.
- From: "René Dudfield" <renesd@xxxxxxxxx>
- Date: Mon, 13 Aug 2007 09:33:49 +1000
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Sun, 12 Aug 2007 19:33:59 -0400
- Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ef75PkXRsirt/bhYWJy1coscjhkBiPPiJxJsXC3389ncltj+4siritKwOAKB8/3/yRuUE+lh+l6bZjbox+qbKgaODGFLYOuymugLYy3D2+4W7SJ+r1lW53ack5qUaBm3hJlzUp1Bt3/rq+UWTRfrAvfCQOeeAc+bXeQyqS+NSm4=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=UUYeCtbk3ySV+j0h7XLpFo8mqPfCmh6l/dO3Dp8hfV2DmB8V7NtZI9mc27IXKOSWs8nJlfK+JHkIUiwRmHpGIPaFPOoGgzefu/YgU1TN5nc+aaUZEDbD3yyIAvk4iil3Cqfv0KZFo+Dp86FybVAuIZo29hq6ymfbx8wkHbtXH2s=
- In-reply-to: <46BC68D1.4060600@xxxxxxxxxx>
- References: <64ddb72c0708091321h7f478b81s87d7c18c8abae07@xxxxxxxxxxxxxx> <46BC68D1.4060600@xxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Thanks DR0ID.
Per pixel alpha, color key, and per surface alpha are all separate,
it's a SDL constraint.
I'll have to look into your script a bit more. I think maybe the
rotate/rotozoom functions need some fixing for non 32bit per pixel
alpha. I'm guessing that the blend modes for blit are ok.
Cheers,
On 8/10/07, DR0ID <dr0id@xxxxxxxxxx> wrote:
> René Dudfield schrieb:
> > Hi,
> >
> > DR0ID, do you have a script which demonstrates this bug?
> >
> > Or can you explain it further?
> >
> >
> Hi
>
> there you have a script. Blendmodes only work with pygame1.8. Users
> using pygame1.7 can start the script, but should not change the
> blendmode pressing 'm'.
>
> Perhaps I have done something wrong, please correct any mistake you
> find. Or perhaps I have forgotten an interesting case.
>
> Results:
>
> rotate() screws up on normals surfaces and surfaces with per surface alpha.
>
> rotozoom() screws up all except surfaces with per pixel alpha
>
> Blendmodes do not respect colorkey nor per pixel alpha. I do not know if
> this is intentional.
>
> rotozoom fills the space in with black, therefore you will not see any
> difference in blendmodes 'add' or 'sub' (because adding 0 or subtracting
> 0 gives the same number).
>
> An is there a reason why colorkey and per pixel alpha are mutual
> exclusive? (is that a constraint from SDL?)
>
> ~DR0ID
>
> #Copyright 2006 DR0ID <dr0id@xxxxxxxxxx> http://mypage.bluewin.ch/DR0ID
> #
> #
> #
> """
> gradients demo
> """
>
> __author__ = "$Author: DR0ID $"
> __version__= "$Revision: 106 $"
> __date__ = "$Date: 2007-08-09 17:43:42 +0200 (Do, 09 Aug 2007) $"
>
>
> import pygame
> import math
> import random
> import os
>
>
>
>
>
>
> def main():
> screen_size = (800,700)
> size = 100 # size of the test surfaces
> fill_color = (0,255,0)
> num_table = (4, 4) # number of test surfaces per row/column
>
> pygame.init()
> os.environ['SDL_VIDEO_CENTERED'] = '1'
> screen = pygame.display.set_mode(screen_size, pygame.SRCALPHA)
> bgd = pygame.Surface(screen.get_size())
> bgd.fill((128,128,128))
> screen.blit(bgd, (0,0))
> font = pygame.font.Font(None, 30)
> surfaces = []
>
> surfaces.append(pygame.Surface((size,)*2)) #normal surface
>
> colorkey = pygame.Surface((size,)*2)#colorkey
> colorkey.set_colorkey((255,0,255))
>
> surfaces.append(colorkey) # colorkey
>
> surfaces.append(pygame.Surface((size,)*2).convert_alpha()) #alpha surface, per pixel alpha
> ## surfaces[-1].set_colorkey((255,0,255))
> ## surfaces[-1].set_alpha(128)
> surf_alpha = pygame.Surface((size,)*2)
> surf_alpha.set_alpha(128)
> surfaces.append(surf_alpha) #alpha surface, per pixel alpha
>
> for idx, surf in enumerate(surfaces):
> surf.fill(fill_color)
>
> pygame.draw.circle(surfaces[1], (255,0,255), (20,20), size/2)
> pygame.draw.circle(surfaces[2], (255,0,255,0), (20,20), size/2)
> ## pygame.draw.circle(surfaces[3], (255,0,255,0), (20,20), size/2)
>
> for idx in range(num_table[0]):
> surfaces.append( pygame.transform.rotate(surfaces[idx], 30))
>
> for idx in range(num_table[0]):
> surfaces.append( pygame.transform.rotozoom(surfaces[idx], 30,1))
>
>
>
> modes = [0,1,2,3,4,5]
> mode = 0
>
> pygame.display.set_caption( "mode:"+str(modes[mode])+
> " keys: m"
> )
> running = True
> changed = True
> while running:
> event = pygame.event.wait()
> if pygame.QUIT==event.type:
> running = False
> elif pygame.KEYDOWN == event.type:
> if event.key == pygame.K_ESCAPE:#pygame.K_ESCAPE == event.key:
> running = False
> elif event.key == pygame.K_m:
> mode += 1
> mode %= len(modes)
> changed = True
> elif pygame.MOUSEBUTTONDOWN == event.type:
> if pygame.key.get_mods()&pygame.KMOD_CTRL:
> spoint = list(pygame.mouse.get_pos())
> else:
> epoint = list(pygame.mouse.get_pos())
> changed = True
>
> if changed:
> changed = False
> mode_str = ["normal", "add", "sub", "mult", "min", "max"]
> pygame.display.set_caption( "mode:"+mode_str[modes[mode]]+
> " keys: m"
> )
> screen.fill((50,50,50))
> screen.blit(bgd, (0,0))
>
> #here blit the different surfaces
> distx = screen_size[0]/num_table[0]
> disty = screen_size[1]/num_table[1]
> idx = 0
> for y in range(0,600, disty):
> for x in range(0,800, distx):
> if idx<len(surfaces):
> if modes[mode]==0:
> screen.blit(surfaces[idx], (x+50,y+50))
> else:
> screen.blit(surfaces[idx], (x+50,y+50), None, modes[mode])
> idx += 1
>
> # strings
> if y == 0:
> if x == 0:
> tex = font.render('normal', 1,(255,255,255))
> screen.blit(tex, (x+50, y))
> elif x == distx:
> tex = font.render('colorkey', 1,(255,255,255))
> screen.blit(tex, (x+50, y))
> elif x == 2*distx:
> tex = font.render('per pixel alpha', 1,(255,255,255))
> screen.blit(tex, (x+50, y))
> elif x == 3*distx:
> tex = font.render('surface alpha 128', 1,(255,255,255))
> screen.blit(tex, (x+20, y))
> if x == 0:
> if y == 0:
> tex = font.render('no rotation', 1 , (255,255,255))
> screen.blit(tex, (x, y+30))
> if y == disty:
> tex = font.render('rotate()', 1 , (255,255,255))
> screen.blit(tex, (x, y+30))
> if y == 2*disty:
> tex = font.render('rotozoom()', 1 , (255,255,255))
> screen.blit(tex, (x, y+30))
> tex = font.render('press m to change blendmode: '+mode_str[modes[mode]], 1 , (255,255,255))
> screen.blit(tex, (screen_size[1]/3, screen_size[1]-50))
>
>
> pygame.display.flip()
>
>
> pygame.quit()
>
>
>
>
>
> if __name__ == '__main__':
> main()
>