Pygame fullscreen is zoomed in

Viewed 255

I'm not sure if this is a known issue with pygame but it seems like it zooms in when I use fullscreen. My monitor resolution is 1920 by 1080. Let me show you some code and the output I get from it.

import pygame, sys
from pygame.locals import *

pygame.init()
clock = pygame.time.Clock()

monitor_size = pygame.display.list_modes()[0]
print(monitor_size)
# Output: 1920x1080

FPS = 30
WINDOW_SIZE = (768, 432) # Proportional to 1920x1080, so it doesn't stretch out
SCREEN_SIZE = WINDOW_SIZE
window = pygame.display.set_mode(WINDOW_SIZE)
pygame.display.set_caption('Project')
screen = pygame.Surface(SCREEN_SIZE)

full_screen = False

def display_corners(surface):
    pygame.draw.aaline(surface, (255, 0, 0), (SCREEN_SIZE[0] - 1, 0), (SCREEN_SIZE[0] - 1, SCREEN_SIZE[1] - 1))
    pygame.draw.aaline(surface, (255, 0, 0), (0, SCREEN_SIZE[1] - 1), (SCREEN_SIZE[0] - 1, SCREEN_SIZE[1] - 1))
    pygame.draw.aaline(surface, (255, 0, 0), (0, 0), (SCREEN_SIZE[0] - 1, 0))
    pygame.draw.aaline(surface, (255, 0, 0), (0, 0), (0, SCREEN_SIZE[1] - 1))


while True:
    # Event Loop ------------------------------------------------- #
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        if event.type == KEYDOWN:
            if event.key == K_F5:
                full_screen = not full_screen
                if full_screen:
                    window_size_before = WINDOW_SIZE
                    WINDOW_SIZE = monitor_size
                    WINDOW = pygame.display.set_mode(WINDOW_SIZE, pygame.FULLSCREEN)
                
                else:
                    WINDOW_SIZE = window_size_before
                    WINDOW = pygame.display.set_mode(WINDOW_SIZE)

   
    # Rendering ------------------------------------------------- #
    screen.fill((10, 10, 10))
    display_corners(screen)
    
    if not full_screen:
        window.blit(pygame.transform.scale(screen, WINDOW_SIZE), (0,0))
    else:
        window.blit(pygame.transform.scale(screen, (WINDOW_SIZE[0], WINDOW_SIZE[1])), (0,0))
    # Update ---------------------------------------------------- #
    pygame.display.update()
    clock.tick(FPS)

So I have a pretty basic full screen feature. But, when I set the monitor_size variable to my monitor size, I can't see the red lines that should be display on the sides of the screen when I'm in fullscreen mode. Even if I'm using my exact monitor size. But with a little of trial and error, I got the perfect monitor size which is 1600 by 900, which also do use the same proportions, so that makes sense. I got this by using monitor_size = pygame.display.list_modes()[2]. But it doesn't make sense to me on why the 1920x1080 (or pygame.display.list_modes()[0]) resolution wasn't the perfect size, I feel like I'm not using the full potential of my screen by using 1600 by 900.

2 Answers

Have you looked into testing with RESIZABLE imported from pygame.locals

screen = pygame.display.set_mode(WINDOW_SIZE, RESIZABLE)

Try making a setting which users could manually choose screen size since many displays differ from each other.

Related