Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparency with pygame.draw #2713

Open
oddbookworm opened this issue Feb 8, 2024 · 1 comment
Open

Transparency with pygame.draw #2713

oddbookworm opened this issue Feb 8, 2024 · 1 comment
Labels
draw pygame.draw

Comments

@oddbookworm
Copy link
Member

pygame.draw doesn't apply transparency, but the docs imply it should

reproducer

import pygame

screen = pygame.display.set_mode((500, 500))

OPAQUE = (255, 0, 0, 255)
TRANSLUCENT = (255, 0, 0, 128)
TRANSPARENT = (255, 0, 0, 0)

opaque_rect = pygame.Rect(0, 0, 100, 100)
translucent_rect = pygame.Rect(100, 0, 100, 100)
transparent_rect = pygame.Rect(200, 0, 100, 100)


running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    screen.fill("black")
    pygame.draw.rect(screen, OPAQUE, opaque_rect)
    pygame.draw.rect(screen, TRANSLUCENT, translucent_rect)
    pygame.draw.rect(screen, TRANSPARENT, transparent_rect)
    pygame.display.flip()

image

@Matiiss
Copy link
Member

Matiiss commented Feb 8, 2024

draw functions do apply the alpha, but in SDL's BLENDMODE_NONE fashion, which means it replaces target alpha. The display surface doesn't have an alpha channel so that gets ignored. If you draw to a SRCALPHA surface and blit that, it will blend properly (as is default behaviour for blitting).

I guess this might benefit from clarification in the docs (maybe an example), but it's not a bug.

Here is a relevant issue about adding a blendmode kwarg to draw functions: #2220

@MyreMylar MyreMylar added the draw pygame.draw label May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
draw pygame.draw
Projects
None yet
Development

No branches or pull requests

3 participants