Comments (7)
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,
- Try upgrading the pygame version
- Ensure graphics driver is up-to-date
- 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. - Try different windowing system. may be
pygame.window.WindowMacOSX
from pygame.
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.
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.
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.
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 sdl2flags = pygame.SCALEDinitial_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 wantIf 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.
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.
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)
- pip install pygame HOT 4
- pygame crash when using cv2, decord together. Segmentation fault (core dumped) HOT 2
- ju8eugo
- e HOT 3
- Unexpected Full Screen Behaviour HOT 16
- Disable the inappropriate self-promotion message on importing pygame HOT 1
- SysFont on Windows clobbers base fonts with alternate styled versions
- pip install pygame HOT 1
- pip install pygame
- car game HOT 1
- 増毛
- 増毛2
- Window Resizing Issue HOT 4
- djkhf
- install with pip with --only-binary :all: HOT 1
- doom
- mosa
- Tried following install guide on docs for MacOS
- Issues running Pygame on my New MacBook Pro HOT 2
- Super HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pygame.