3

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

Aemyl
  • 1,501
  • 1
  • 19
  • 34
  • 2
    On Linux I get the *expected* version. Do you have screen-scaling / HiDPI display turned on or suchlike? – Kingsley Mar 10 '19 at 23:34
  • @Kingsley I don't know how to figure that out, but I certainly didn't change the default settings – Aemyl Mar 11 '19 at 05:42
  • 1
    I also get the expected version on Windows 10. If you take a [screen shot of your pygame window](https://stackoverflow.com/questions/17267395/how-to-take-screenshot-of-certain-part-of-screen-in-pygame) and look at it in an image editor, match what you expect? Perhaps view the image on a different machine to compare. – import random Mar 12 '19 at 01:18
  • 1
    @Eric taking a screenshot with `pygame.image.save(self.screen, "screenshot.bmp")` gave the expected result – Aemyl Mar 12 '19 at 16:26

1 Answers1

3

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

Aemyl
  • 1,501
  • 1
  • 19
  • 34