Wrong colors antialiasing with Pygame on OS X

谁说胖子不能爱 提交于 2019-12-10 15:24:10

问题


I'm using Pygame on a Macbook Pro (non-retina) running OS X. When I try to create an antialiased line or circle, it seems to be coming out as the wrong color. Here's an example:

import sys, pygame, random, math
import pygame.gfxdraw

black = (0,0,0)
white = (255, 255, 255)
green = (0, 255, 0)


pygame.init()

size = width, height = 800, 600

screen = pygame.display.set_mode(size)

# make the background
background = pygame.Surface(screen.get_size())
#background.fill(black)
background.fill(white)

while 1:
    # handle single events
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE: sys.exit()

    screen.blit(background, (0, 0))

    pygame.draw.line(screen, green, [0, 0], [50,30], 1)
    pygame.draw.aaline(screen, green, [0, 50],[50, 80], True)

    pygame.draw.circle(screen, black, [100, 100], 10)
    pygame.gfxdraw.aacircle(screen, 100, 130, 10, black)

    pygame.display.flip()

Which leads to:


回答1:


Haven't been able to find the cause for this despite searching through the pygame source code.

I did manage to come up with a workaround though. Two actually.

There seems to be a bug in the pygame.gfxdraw module that causes colors to be messed up in OS X when the value for blue is 0. If you change your black to (0,0,1), the circle will already look much better, but still have a slight blueish tinge. Change it to (0,0,2) and it will appear pretty much completely black. Makes little sense to me but it works.

Edit: That's for background colors that don't contain any blue. It appears that on background RGBs containing >0 blue, the circle needs at least that amount of blue to prevent the bug. For example, to get a black aacircle on a (50,50,50) background, the closest I was able to get was by using (0,0,50) for the circle. Any lower amount of blue will result in bright blue artifacts.

Adding blue doesn't help for fixing pygame.draw.aaline's behavior though. This must be a separate bug. However, pygame.gfxdraw.line is also anti-aliased. Use that method instead, change green to (0,255,1) and the cyan line will now be green.



来源:https://stackoverflow.com/questions/24208783/wrong-colors-antialiasing-with-pygame-on-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!