[SOLVED] Tearing in SDL

[SOLVED] Tearing in SDL

Postby Buch » 01 Feb 2013, 14:16

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?
Last edited by Buch on 01 Feb 2013, 18:19, edited 1 time in total.
User avatar
Buch
 
Posts: 51
Joined: 15 Jan 2013, 14:30
Location: Castel del Piano, Grosseto, Italy

Re: Tearing in SDL

Postby charlie » 01 Feb 2013, 16:55

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.
Free Gamer - it's the dogz
Vexi - web UI platform
User avatar
charlie
Global Moderator
 
Posts: 2131
Joined: 02 Dec 2009, 11:56
Location: Manchester, UK

Re: Tearing in SDL

Postby Buch » 01 Feb 2013, 17:12

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...
User avatar
Buch
 
Posts: 51
Joined: 15 Jan 2013, 14:30
Location: Castel del Piano, Grosseto, Italy

Re: Tearing in SDL

Postby NaN » 01 Feb 2013, 17:59

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?
NaN
 
Posts: 151
Joined: 18 Jan 2010, 10:32

Re: Tearing in SDL

Postby Buch » 01 Feb 2013, 18:19

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!
User avatar
Buch
 
Posts: 51
Joined: 15 Jan 2013, 14:30
Location: Castel del Piano, Grosseto, Italy

Who is online

Users browsing this forum: No registered users and 1 guest