[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] performance issues



Jon Peirce wrote:

I'm having a couple of performance issues using pygame (basically as a context for opengl drawing).
I'm running on a windows box (3GHz P4 with NVidia FX5200 on a CRT display), and I generally synch buffer-swaps to the frame.

1) If I create my pygame display in fullscreen mode it defaults to 60Hz refresh rate which is no good for my purposes. The same code running windowed inherits the monitor rate, which is fine. Using GLUT instead of pygame there's no problem so it isn't something inherent to my system. Is there any way to control frame rate programatically, or at least to force it keep at the same rate as before?

SDL tries to be safe when choosing the refresh rate. So it chooses the lowest value. afaik there is no way in sdl to choose refresh rate. There has been talk of it on the sdl mailing list of fixing this, not sure if anything has made it into the source yet(maybe try asking on that list).

Did a bit of searching and found that some people are calling platform specific functions themselves.
There is one here for windows which uses ctypes: http://aspn.activestate.com/ASPN/Mail/Message/wxPython-users/1684800

I remember there was a patch for xfree86, but I can't find it.

If you want to make a patch for this yourself, maybe the glut sources would be a good source of information.

2) After a few seconds there's a significant disk access that causes a frame rate drop (regardless of what/how much I draw to the screen). Maybe a module is being initialised late - after I've already started drawing? Does anyone else have this problem?

For game development these probably wouldn't be a problem but I'm using it for visual stimuli (www.psychopy.org) and timing needs to be precise. Below is minimal code for demo.

Jon


Can you wait until the disk access has past? Does it happen on different platforms/systems?

Maybe try gdb or some other debugger with break points set on fread, fwrite etc.

If you don't need sound/music etc, try only initialising the parts of pygame you need. eg pygame.display.init() This means that pygame doesn't use any threads(I think). It may help, who knows!


#-------------------------------------------------
import pygame
from OpenGL import GL

#setup pygame
pygame.init()
winSettings = pygame.OPENGL
#winSettings = winSettings|pygame.FULLSCREEN
myWin = pygame.display.set_mode([800,600],winSettings)

#setup openGL
GL.glClearColor(1.0, 1.0, 1.0, 1.0)
GL.glClear(GL.GL_COLOR_BUFFER_BIT)
      pygame.display.flip()
pygame.time.delay(10000)

pygame.quit()

This example doesn't run.  How it would show either problem?


Have fun!