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

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



I tried this again with this in the main loop:

for i in xrange(1000):
    screen.fill( (0,0,0) )
    t=(pygame.time.get_ticks()*240)//1000
    for r in rectangles:
        screen.fill( (255,0,0), r.move(-t,-t) )
    realscreen.blit(screen,(0,0))
    pygame.display.flip()

It is indeed a fair bit smoother. Thanks for the advice. It looks not
bad so long as I can sustain frame-rates >200fps. I think the problem
is that if I'm scrolling at 6 pixels per frame then when tearing
occurs it's a jarring 6 pixels wide. If I render many times faster
than the refresh rate then tearing will still occur but most of the
time it will only be 1 pixel wide. But if I run at higher resolutions
my frame-rate drops and even though I could sustain >60fps it still
looks bad because it's not synchronised. :-/

I would include an example of my game code, but it's very messy at the
moment and the first example really does show up the problem fairly
accurately on my machine. Two or three times every second a band of
tearing sweeps up the screen, and the otherwise smoothly moving
background appears to jump forward a few pixels as the band crosses
it. This is pretty much what I'd expect without vsync.

On Mon, Feb 23, 2009 at 6:34 PM, Casey Duncan <casey@xxxxxxxxxxx> wrote:
> 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.
>
>