Search code examples
pythonpygameantialiasing

Disabling anti-aliasing in pygame


I have tried to set single pixels in pygame with pygame.PixelArray. Unfortunately, It looks like pygame automatically anti-aliases those pixels. This is what I have tried so far:

import pygame


BLACK = (0, 0, 0)
BLUE  = (0, 0, 255)
WHITE = (255,255,255)


class GUI:

    def __init__(self):

        self.screen = pygame.display.set_mode((300, 300))
        pygame.mouse.set_visible(True)
        self.clock = pygame.time.Clock()

    def gameloop(self):

        running = True
        while running:
            self.screen.fill(WHITE)
            # event handling
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False
            # drawing
            # for some reason, everything gets anti-aliased
            pixel_array = pygame.PixelArray(self.screen)
            pixel_array[100][100] = BLACK
            pixel_array[100][101] = BLUE
            pixel_array[101][100] = BLUE
            pixel_array[101][101] = BLACK
            del pixel_array
            # update full display
            pygame.display.flip()
            self.clock.tick(30)


def main():

    pygame.init()
    gui = GUI()
    gui.gameloop()
    pygame.quit()


if __name__ == '__main__':

    main()

What I have got:

anti-aliased pixels

What I expected to get:

pixels

System:

Python version: 3.7.2 (64-bit)
OS: Windows 10 Home Version 1803 Build 17134.590
pygame version: 1.9.4
Display: Integrated in Lenovo-Laptop (1920 x 1080)
Processor: Intel-Core-i5-6300HQ
IGP: Intel HD Graphics 530
GPU: Nvidia GeForce GTX 960M


Solution

  • After a hint from Eric, I figured out that the problem wasn't caused by pygame, but by the display resolution settings. The display was scaled to 125% by default.

    I don't know how to describe where you can find these settings in english since my Windows is set to german, so I made screenshots:

    settings settings2