1

Ok, so I have been using a special_flags BLEND_MULT surface to add some lighting to a little game I am making in pygame.

The works fine when the program is windowed however, whenever I try to make the Window Fullscreen the BLEND surface does not fullscreen with the rest of the components, it just extends off the edge of the screen. Therefore any gradients blitted to the BLEND surface are also in the wrong position.

This image shows the error when I have the Window Full screened

I know this is an issue with the special_flags (and not me blitting the surface incorrectly) because when I remove the special_flags parameter the surface Fills screens perfectly with the rest of the components

This image shows the window correctly Full screening

Basically I am asking for a way to fix this bug so that I can keep the special_flags parameter without it breaking on Full screen. this way I don't have to completely redo my lighting.

Here is the code which draws surface (fog surface) to the game display

def render_fog(self):
    #draw light onto fog
    for fog in self.all_fog:
        fog.image.fill(fog.colour)
        self.light_rect.centerx = self.player.rect.centerx - fog.x
        self.light_rect.centery = self.player.rect.centery - fog.y
        fog.image.blit(self.light_mask, self.light_rect)
        for light in self.all_light:
            light.centerx = light.x 
            light.centery = light.y
            fog.image.blit(light.image, (light.rect))
        self.gameDisplay.blit(fog.image, (fog.x, fog.y), special_flags = pygame.BLEND_MULT)

Here is an example that shows the same error when going fullscreen, just simply press f to do so

import pygame
import sys
from os import path
from time import sleep
import random

WIDTH = 864
HEIGHT = 512
NIGHT_COLOR = (20, 20, 20)
RED = (255, 0, 0)

class Game:
    def __init__(self):
        pygame.init()
        self.gameDisplay = pygame.display.set_mode((WIDTH, HEIGHT))
        self.clock = pygame.time.Clock()

        self.running = True
        self.fullscreen = False

        self.load_data()

    def load_data(self):
        self.fog = pygame.Surface((WIDTH, HEIGHT))
        self.fog.fill(NIGHT_COLOR)

    def quit(self):
        pygame.quit()
        sys.exit()

    def run(self):
        self.playing = True
        while self.playing:
            self.dt = self.clock.tick(60) / 1000
            self.events()
            self.draw()

    def events(self):
        for e in pygame.event.get():
            if e.type == pygame.QUIT:
                self.quit()

            if e.type == pygame.KEYDOWN:
                if e.key == pygame.K_f:
                    self.fullscreen = not self.fullscreen

    def render_fog(self):
        self.fog.fill(NIGHT_COLOR)
        self.gameDisplay.blit(self.fog, (0, 0), special_flags = 
pygame.BLEND_MULT)


    def draw(self):
        pygame.display.set_caption("FPS: 
{:.2f}".format(self.clock.get_fps()))

        if self.fullscreen:
            self.gameDisplay = pygame.display.set_mode((864, 512), 
pygame.FULLSCREEN)
        else:
            self.gameDisplay = pygame.display.set_mode((864, 512))

        self.gameDisplay.fill(RED)
        self.render_fog()     
        pygame.display.update()

g = Game()
while g.running:
g.run()
Sam Barnes
  • 11
  • 2
  • Please post a [minimal, complete and verifiable example](https://stackoverflow.com/help/mcve). We'll probably need the images as well. – skrx Aug 23 '17 at 14:07
  • I have added an example that shows the same error, I cannot embed the images so links are provided – Sam Barnes Aug 23 '17 at 16:07
  • I've experimented a bit but I'm not sure what's actually going on when you use the fullscreen mode in Python (I usually use only the windowed mode). The display seems to get stretched somehow. The docs say: *"When requesting fullscreen display modes, sometimes an exact match for the requested resolution cannot be made. In these situations pygame will select the closest compatible match. The returned surface will still always match the requested resolution."* – skrx Aug 24 '17 at 18:46
  • 1
    I've found a short term solution for fixing the problem, however it does require the resolution for the game to be changed. As you said when pygame goes full screen it will try to find a resolution to the closest compatible match, therefore the resolution of the game has to match this to prevent the bug. For example, with my current resolution at 864 X 512 when pygame goes full screen it upscale to the nearest compatible resolution, being 1024 X 768 (because its a 32 bit game), this causes the bug to occur. If I change the resolution to a compatible resolution, it fixes the bug – Sam Barnes Aug 24 '17 at 22:59

0 Answers0