Git Product home page Git Product logo

Comments (7)

Namitha-KS avatar Namitha-KS commented on June 5, 2024 1

This error message typically pops in due to some compatibility issues with the os or versions of the libraries. To resolve the issue you may,

  1. Try upgrading the pygame version
  2. Ensure graphics driver is up-to-date
  3. Try using different flags. In the above code, .HIDDEN means that the window will be hidden after creation. This is often used when you want to create a window off-screen, perform some operations, and then show it later.
  4. Try different windowing system. may be pygame.window.WindowMacOSX

from pygame.

semibran avatar semibran commented on June 5, 2024

been getting a similar error on windows, seems to work fine with 2.4.0 but not >=2.5.0 (though this may be a completely separate issue)

from pygame.

Namitha-KS avatar Namitha-KS commented on June 5, 2024

Have you tried manually scaling it with the pygame._sdl2 (mentioned in the doc) or you could try something like this:

import pygame
import pygame._sdl2 as sdl2
flags = pygame.SCALED
initial_scale_factor = 3 # <-- adjustable
window = sdl2.Window.from_display_module()
window.size = (WIN_WIDTH * initial_scale_factor, WIN_HEIGHT * initial_scale_factor)
window.position = sdl2.WINDOWPOS_CENTERED
window.show()

This works without the pygame.RESIZABLE module and should give a scaled window with whatever initial scale factor you want

If you encounter issues with _sdl2 or need a more stable approach, try manual scaling within Pygame's core API using surface transformations or resizing techniques.

from pygame.

jamespblloyd-uwa avatar jamespblloyd-uwa commented on June 5, 2024

been getting a similar error on windows, seems to work fine with 2.4.0 but not >=2.5.0 (though this may be a completely separate issue)

Thanks but when I try a new conda/mamba env with an older pygame version, it still does not work for me:
pygame 2.4.0 (SDL 2.28.5, Python 3.8.18)

from pygame.

jamespblloyd-uwa avatar jamespblloyd-uwa commented on June 5, 2024

Have you tried manually scaling it with the pygame._sdl2 (mentioned in the doc) or you could try something like this:

import pygame
import pygame._sdl2 as sdl2
flags = pygame.SCALED
initial_scale_factor = 3 # <-- adjustable
window = sdl2.Window.from_display_module()
window.size = (WIN_WIDTH * initial_scale_factor, WIN_HEIGHT * initial_scale_factor)
window.position = sdl2.WINDOWPOS_CENTERED
window.show()

This works without the pygame.RESIZABLE module and should give a scaled window with whatever initial scale factor you want

If you encounter issues with _sdl2 or need a more stable approach, try manual scaling within Pygame's core API using surface transformations or resizing techniques.

Thanks for getting back to me. I can successfully import pygame._sdl2 as sdl2 so that is a nice start. I do not know how to integrate this into my existing code:

initial_scale_factor = 3 # <-- adjustable
window = sdl2.Window.from_display_module()
window.size = (WIN_WIDTH * initial_scale_factor, WIN_HEIGHT * initial_scale_factor)
window.position = sdl2.WINDOWPOS_CENTERED
window.show()

Does this replace any of my existing code like:

self.screen = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT), flags = pygame.SCALED)
    def draw(self):
        self.screen.fill(BLACK)
        self.all_sprites.draw(self.screen)
        self.clock.tick(FPS)
        pygame.display.update()

I am not sure how window interacts with screen and the calling of screen in my code (sorry new to pygame and any coding other than for simple bioinformatics).

from pygame.

Namitha-KS avatar Namitha-KS commented on June 5, 2024

Yes, you can replace the line where you set the display mode with the SDL2 code. Here's how you can integrate it into your existing code:

import pygame
import pygame._sdl2 as sdl2

BLACK = (0, 0, 0)
WIN_WIDTH, WIN_HEIGHT = (256, 128)
FPS = 60

class Game:
    def __init__(self):
        pygame.init()

        flags = pygame.SCALED
        flags |= pygame.RESIZABLE  # optional

        pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT), flags | pygame.HIDDEN)

        initial_scale_factor = 3  # <-- adjustable
        window = sdl2.Window.from_display_module()
        window.size = (WIN_WIDTH * initial_scale_factor, WIN_HEIGHT * initial_scale_factor)
        window.position = sdl2.WINDOWPOS_CENTERED
        window.show()

        self.screen = pygame.Surface((WIN_WIDTH, WIN_HEIGHT))
        self.clock = pygame.time.Clock()  
        self.all_sprites = pygame.sprite.Group()  

    def draw(self):
        self.screen.fill(BLACK)
        self.all_sprites.draw(self.screen)

game = Game()

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    game.draw()
    pygame.display.flip()
    game.clock.tick(FPS)
pygame.quit()

I use VSCode as my IDE and this code works for me. Pygame is an amazing library to start with and it is fun. About the window interaction, try referring to youtube tutorials.

from pygame.

jamespblloyd-uwa avatar jamespblloyd-uwa commented on June 5, 2024

Thanks for getting back to me Namitha-KS.

I can run the above code without an error message and I get a small black window. But when I added the relevant code to my larger script, I get the same error:
python main.py pygame 2.5.2 (SDL 2.28.5, Python 3.12.1) Hello from the pygame community. https://www.pygame.org/contribute.html Traceback (most recent call last): File "/Users/jameslloyd/Documents/Main_Work_JPBL/Non_work/Hobbies/Game_dev/pygame/Building_RPG_Game_example/My_first_game_attempt/main.py", line 149, in <module> game = Game() ^^^^^^ File "/Users/jameslloyd/Documents/Main_Work_JPBL/Non_work/Hobbies/Game_dev/pygame/Building_RPG_Game_example/My_first_game_attempt/main.py", line 43, in __init__ pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT), flags | pygame.HIDDEN) pygame.error: failed to create renderer

I am not sure what pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT), flags | pygame.HIDDEN) is supposed to be doing here as it contains the pygame.SCALED that always causes the error for me. When I remove this line from my code, or just remove the flags, I just get a super large black screen. So I am not sure what I am doing wrong here but sadly it has not solved the issue.

Thank you again for trying!

from pygame.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.