Search code examples
pythonfullscreenpygamepyopengl

PyOpenGL + Pygame capped to 60 FPS in Fullscreen


I'm currently working on a game engine written in pygame and I wanted to add OpenGL support.

I wrote a test to see how to make pygame and OpenGL work together, and when it's running in windowed mode, it runs between 150 and 200 fps. When I run it full screen (all I did was add the FULLSCREEN flag when I set up the window), it drops down to 60 fps. I added a lot more drawing functions to see if it was just a huge performance drop, but it always ran at 60 fps.

Is there something extra I need to do to tell OpenGL that it's running fullscreen or is this a limitation of OpenGL?

(I am running in Windows XP)


Solution

  • As frou pointed out, this would be due to Pygame waiting for the vertical retrace when you update the screen by calling display.flip(). As the Pygame display documentation notes, if you set the display mode using the HWSURFACE or the DOUBLEBUF flags, display.flip() will wait for the vertical retrace before swapping buffers.

    To be honest, I don't see any good reason (aside from benchmarking) to try to achieve a frame rate that's faster than the screen's refresh rate. You (and the people playing your game) won't be able to notice any difference in speed or performance, since the display can only draw 60 fps anyways. Plus, if you don't sync with the vertical retrace, there's a good chance that you'll get screen tearing.