[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.



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()