[SDL] tearring graphics

Atrix Wolfe atrix2 at cox.net
Wed Jan 29 10:15:02 PST 2003

another idea would be something like when you hold down a button, your game
enters some kinda "pause" mode where it doesnt update anything that would
cause the graphics to change, allowing you to take a screen shot because
even if tearing happens, you cant see it since its just the same frame over
and over.  Pressing the button again would take it out of pause mode.

----- Original Message -----
From: "David Olofson" <david at olofson.net>
To: <sdl at libsdl.org>
Sent: Wednesday, January 29, 2003 8:26 AM
Subject: Re: [SDL] tearring graphics

On Wednesday 29 January 2003 05.44, Chris Thielen wrote:
> Just a simple question: how do you (anybody who cares to respond)
> avoid tearring graphics? Is it as simple as passing SDL_DOUBLEBUF
> to SDL_SetVideoMode() or is there more to it? The game I'm working
> on doesn't have any protection against tearring so generally on
> quick loops you can get screenshots of half the screen drawn with a
> new frame and the old frame still taking up 300 rows down. Any
> suggestions?

Oh, almost forgot: There is *one* trick that can greatly reduce
tearing, when you can't have retrace sync'ed flips: Sub-pixel
accurate rendering.

This more or less requires OpenGL, at least if you want to do
full-screen scrolling, and probably does anyway, as you need frame
rates several times higher than the display refresh rate for this
trick to work well.

What happens is basically that by redrawing the screen over and over,
several times per CRT refresh, using sub-pixel accurate rendering,
each displayed image become slightly "skewed", rather than torn. The
higher the rendering frame rate, the smaller the difference between
each rendered frame - and thus, if the frame rate is high enough, you
won't see the tearing, although it's still there, theoretically.

This is part of the reason why tearing isn't as obvious in 3D games as
it is in 2D games.

Check out "smoothscroll-1.1" at http://olofson.net/mixed.html for a
basic example of sub-pixel accurate rendering with OpenGL. It also
runs in SDL software mode, so you can see the difference. It's really
intended to demonstrate ultra smooth scrolling without designing for
specific refresh rates (which you can't do these days unless you're
into consoles or arcade machines), but also demonstrates that the
same method gives you tearing reduction on non-sync'ed displays as an
extra bonus.

//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`---------------------------> http://olofson.net/audiality -'
   --- http://olofson.net --- http://www.reologica.se ---

SDL mailing list
SDL at libsdl.org

More information about the SDL mailing list