Search code examples
pygamedisplaysurfacepalette

Make the display 8 bit and set palette


I have an 8-bit colour depth surface and some 8-bit colours, and I set the surface up like this:

self.surf = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT)).convert(8)
self.surf.set_palette(self.colours)

I tried to make the display 8-bit so I wouldn't have to blit the surface to it as I wondered if I could just set the pixels on the display screen directly. First I tried:

screen = pygame.display.set_mode(size = (SCREEN_WIDTH, SCREEN_HEIGHT), depth = 8)

and

pygame.display.set_palette(self.colours)

But it said:

pygame.error: Display mode is not colormapped

So I tried:

self.surf = pygame.display.get_surface().convert(8)
self.surf.set_palette(self.colours)

and:

self.surf.set_at((i, index), the_colour)

But nothing seems to work. Is there a way to address the display directly similar to how you can with a surface and set_at?


Solution

  • This is a backwards compatibility bug in pygame 2. https://github.com/pygame/pygame/issues/991.

    You could get around this by downgrading to pygame 1.9.6, but I would recommend staying on pygame 2 to take advantage of all the new features.