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

Re: [pygame] Options for smooth-scrolling in X-Windows



You might try losing the clock.tick_busy_loop(60), I found on MacOS X that I would get tearing frequently if I throttled the framerate arbitrarily, might help on X-win too. Since this is just busy-waiting anyway it might even use less cpu without it, regardless it shouldn't use more.

-Casey

On Feb 23, 2009, at 10:02 AM, Weeble wrote:

I'm trying to do full-screen scrolling, using pygame in X-Windows. As
far as I can tell, there's no way around the problem of tearing. Is
that true? Here's a simple example that gives me problems:

import pygame
from pygame.locals import *
from random import randint

pygame.init()
opts = pygame.FULLSCREEN|pygame.DOUBLEBUF|pygame.HWSURFACE
screen = pygame.display.set_mode((640,480),opts)

rectangles=[Rect(randint(0,1200),randint(0,1200),64,64) for i in xrange(200)]
clock = pygame.time.Clock()

for i in xrange(300):
  screen.fill( (0,0,0) )
  for r in rectangles:
      screen.fill( (255,0,0), r.move(-4*i,-4*i) )
  pygame.display.flip()
  clock.tick_busy_loop(60)

The problem is that the scrolling isn't smooth. There's a noticeable
flicker, resulting from the flip() being unsynchronised with the
screen refresh. (I've experimented with other settings for "opts"
above and I've used both tick and tick_busy_loop with similar
results.) Am I right in thinking that there's no way around this using
the x11 driver? Is there an alternative to this if I want people to be
able to play my game smoothly on Linux? I understand vsync is possible
in OpenGL, but I think that means I'd need to completely change my
rendering code and might have difficulty doing some of the stuff I do
at the moment. (I render between several intermediate surfaces using
various blend modes to do some effects.) Is that also the case? What
approach do people generally take? I can see a number of alternatives:

1. Don't use/support Linux.
2. Avoid scrolling backgrounds, so tearing isn't such a big deal.
3. Use OpenGL for all rendering, abandoning easy to use surfaces.
4. Super magic solution to get working VSYNC under X-windows.

Any advice would be much appreciated.

Regards,
   Weeble.