views:

450

answers:

2

I've been playing with pygame (on Debian/Lenny). It seems to work nicely, except for annoying tearing of blits (fullscreen or windowed mode).

I'm using the default SDL X11 driver. Googling suggests that it's a known issue with SDL that X11 provides no vsync facility (even with a display created with FULLSCREEN|DOUBLEBUF|HWSURFACE flags), and I should use the "dga" driver instead.

However, running

SDL_VIDEODRIVER=dga ./mygame.py

throws in pygame initialisation with

pygame.error: No available video device

(despite xdpyinfo showing an XFree86-DGA extension present).

So: what's the trick to getting tear-free vsynced flips ? Either by getting this dga thing working or some other mechanism ?

+1  A: 

The best way to keep tearing to a minimum is to keep your frame rate as close to the screen's frequency as possible. The SDL library doesn't have a vsync unless you're running OpenGL through it, so the only way is to approximate the frame rate yourself. The SDL hardware double buffer isn't guaranteed, although nice when it works. I've seldomly seen it in action.

In my experience with SDL you have to use OpenGL to completely eliminate tearing. It's a bit of an adjustment, but drawing simple 2D textures isn't all that complicated and you get a few other added bonuses that you're able to implement like rotation, scaling, blending and so on.

However, if you still want to use the software rendering, I'd recommend using dirty rectangle updating. It's also a bit difficult to get used to, but it saves loads of processing which may make it easier to keep the updates up to pace and it avoids the whole screen being teared (unless you're scrolling the whole play area or something). As well as the time it takes to draw to the buffer is at a minimum which may avoid the blitting taking place while the screen is updating, which is the cause of the tearing.

Sir Oddfellow
A: 

Well my eventual solution was to switch to Pyglet, which seems to support OpenGL much better than Pygame, and doesn't have any flicker problems.

timday