pygame
pygame copied to clipboard
Colors come out weird with _sdl2.Texture.update()
Environment:
- Operating system: Windows 10
- Python version: 3.9.6
- SDL version: 2.0.18
- PyGame version: 2.1.2
- Relevant hardware: nVidia GeForce RTX 2080 Ti
Current behavior:
The colours of certain images come out different than expected when using _sdl2.Texture.update. Possibly something to do with image formats. This is using the _sdl2 module.
Expected behavior:
Correctly rendered colours for the image.
Screenshots
The left image is the incorrect one, while the right is correct.
The left is using texture.update() to add a surface to a texture, the right is using the texture.from_surface

The original image:

Steps to reproduce:
- Load png image as surface with
pygame.image.load - Create sdl2 Texture
- Draw surface onto texture with Texture.update()
Test code
import sys, pygame
from pygame import _sdl2
window = _sdl2.Window(size=(1048, 512))
renderer = _sdl2.Renderer(window)
surf = pygame.image.load("lildragon01.png")
# surf = pygame.image.load("lildragon01.bmp") # bmps also come out garbled
# The texture comes out weird with this
texture = _sdl2.Texture(renderer, size=(512, 512))
texture.update(surf, area=surf.get_rect())
# The colours come out correctly with this
texture2 = _sdl2.Texture.from_surface(renderer, surf)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE:
sys.exit()
renderer.clear()
texture.draw(dstrect=surf.get_rect())
texture2.draw(dstrect=(512,0, surf.get_width(), surf.get_height()))
renderer.present()
Zip with the source, BMP and PNG if you'd like to test:
Additionally BMPs comes out like this as well:

Another early adopter!
Oh yeah, and a problem too. I'll look into it sometime.
Be aware of course that the API is unstable. I've written out some of my ideas for changes here: https://github.com/pygame/pygame/issues/2691
Yep all good, I'm used to moving code and I think I'll be here for a couple years if things go well anyway. Also the _sdl2 module is too awesome to not use! haha. Anyway thought I should post some of the issues I find. Should I be posting them here? (Thanks for the link btw)
I think the best approach would be to open the new issue for every bug you encounter, and then we group them with the same tag. Because GitHub is not really a best place for "megathreads". But yea, you should definitely post those issues because that is important for the fix
aah, your (art) is good!