The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Enabling SDL Vsync in Windows
InDilemma


Joined: 29 Jun 2011
Posts: 6
Hi All,

I'm kinda newbie in SDL. My question is; my software runs ~180fps but my screen is 60Hz so I have tearing in my display. I want to enable Vsync in Windows- actually not sure whether it's on or off thou -

Btw It's running full screen and I tried using small delays, or changing SDL_Flip to SDL_UpdateRect but no luck - I don't use OpenGL and my graphics card is nVidia (vSync force is ON).

I'd appreciate any comment or help. Thanks
handcrafter


Joined: 13 Jul 2011
Posts: 3
Use double-buffering.

Code:
SDL_SetVideoMode(yourWidth, yourHeight, yourBpp, SDL_HWSURFACE  | SDL_DOUBLEBUF | SDL_FULLSCREEN);


You must have access to a hardware surface for double buffering to be available. Double buffering does not occur unless you're running in fullscreen mode -- so don't test your framerates in windowed mode. See this article to understand the impact double buffering *may* have on your framerate in this regard.
InDilemma


Joined: 29 Jun 2011
Posts: 6
Hi
Thanks for the reply. I will check again but I think I was already using double buffering. Assuming that I have double buffer, does Vsync runs automaticly ? or is double buffering = Vsync ?

Thanks again
handcrafter


Joined: 13 Jul 2011
Posts: 3
In the article link I posted above:

Quote:
>Why would double buffering reduce your frame rate???


Because it allows SDL to use retrace sync'ed page flips when supported
by the driver. Without double buffering, SDL won't even try to sync.

If the driver doesn't support retrace sync, or it's been disabled,
double buffering (provided it's still h/w page flipping!) should
indeed have insignificant impact on performance.


And please read this thread: http://www.gamedev.net/topic/277119-vsync-in-sdl/

In there they say

Quote:
turning vsync on [meaning for your video card] will sync SDL_Flip with every monitor refresh
you cant turn vsyncon in SDL


Note in the top quote, the poster says "allows". Meaning double buffering enables it (AFAIK), but it has to be turned on for your graphics card. You'll need to figure that part out.

Please anyone correct me if any inaccuracies here.
InDilemma


Joined: 29 Jun 2011
Posts: 6
Thanks handcrafter,

Your explanations made it a lot clear for me. Cheers!