Page 1 of 1

[SOLVED] Tearing in SDL

PostPosted: 01 Feb 2013, 14:16
by Buch
The problem's pretty easy: I'm experiencing tearing in my SDL-based game.

I tried googling for that, and a couple of solutions came out, none of which actually worked.
The first one was enabling double buffering: I tried and it did remove tearing but at the cost of reducing fps from ~200 to ~10...
The other supposed solution was to use framerate independent movement: this solves the problem only on fast computers, while it doesn't AFAIK for slower computers running at ~60 fps.

Is there a way to get past this or it's one of the downsides of SDL programming?

Re: Tearing in SDL

PostPosted: 01 Feb 2013, 16:55
by charlie
Double buffering shouldn't impact your FPS that badly; sounds like you got something slightly wrong there.

It would be good to post a link to your game/code so the problem could be seen.

Re: Tearing in SDL

PostPosted: 01 Feb 2013, 17:12
by Buch
This is what I'm doing:

{l Code}: {l Select All Code}
SDL_putenv("SDL_VIDEODRIVER=directx");//Sets video driver - windows only, working on other systems later

//...other initialization stuff

video = SDL_SetVideoMode(video_w, video_h, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | (fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE));//Creates video surface


I found on some forums that double buffering works only with the right video driver, which in windows is not the default one (see here), that's why I set directx as the video driver. Hardware surfaces and double buffering actually don't work else.

Fps are reduced a lot when I do this. It is not very much of a problem in windowed mode (at list on my pc, even more than 100 fps), but it is in fullscreen mode (where I get those 10 fps of above). And I'd really like to keep fullscreen mode as an option...

Re: Tearing in SDL

PostPosted: 01 Feb 2013, 17:59
by NaN
Are you blitting with alpha blending? This wont work well with SDL_HWSURFACE I think. Look here: http://forums.libsdl.org/viewtopic.php? ... b1a5e69130

You could try to draw/blend into an extra swsurface first and then copy it to your hwsurface(screen).

Have you considered using hardware acceleration (OpenGL) for drawing?

Re: Tearing in SDL

PostPosted: 01 Feb 2013, 18:19
by Buch
Thank you man! This allowed to reach ~60 fps in fullscreen mode and removed tearing... I guess with smaller resolutions this should go faster, so it's ok... Thanks for quick solution!