SDL + OpenGL V-Sync

Started by
15 comments, last by Tolito 11 years, 2 months ago

When I was using SDL alone for the graphics, SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); did the job, but now that I am using SDL as a container for OpenGL, with OpenGL being used for graphics, it does not work and the problem is back. I have been looking for a solution for a little over an hour now but I have had no luck. Is there a simple, cross-platform solution that I am missing here? I would like to be able to do it using what is already available in SDL.h and SDL_opengl.h. I have tried including glx.h, using the -glx compiler flag, and using glXSwapIntervalEXT(1);, but I received an undefined reference to that and want to avoid using extensions anyway (so I don't have to worry about different ones for different platforms and all of that). Thank you! :)

Advertisement

The easiest way to do this is to add Sleep(17); in your main loop. This will cap your framerate to 60 and you will have kind of v-sync. For me also works SDL_GL_SetSwapInterval((int)vsync); this will cap your framerate to refresh rate of the screen and you will have v-sync.

glXSwapIntervalEXT is not crossplatform, for win you should call wglSwapIntervalEXT. Also, if I am not mistaken, for glXSwapIntervalEXT you should link against libX11 as -lX11

Also you can look at this post: http://forums.libsdl.org/viewtopic.php?p=24220&sid=a85c51359b9040234fece5114e1d5787#24220

The easiest way to do this is to add Sleep(17); in your main loop. This will cap your framerate to 60 and you will have kind of v-sync. For me also works SDL_GL_SetSwapInterval((int)vsync); this will cap your framerate to refresh rate of the screen and you will have v-sync.

I have been already been capping my framerate. I get an undefined reference to SDL_GL_SetSwapInterval when I try calling that. Thank you for your response!

glXSwapIntervalEXT is not crossplatform, for win you should call wglSwapIntervalEXT. Also, if I am not mistaken, for glXSwapIntervalEXT you should link against libX11 as -lX11

Also you can look at this post: http://forums.libsdl.org/viewtopic.php?p=24220&sid=a85c51359b9040234fece5114e1d5787#24220

The fact that they are not cross-platform is one of the reasons I want to avoid using them. Thanks for the linker settings and the link! The post you linked to appears to be using SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); for versions of SDL that are not at least 1.3.0. I have used that and still have no luck. Do you suggest using SDL 1.3.0? Thanks for responding!

I get an undefined reference to SDL_GL_SetSwapInterval when I try calling that.

Sorry, forgot to mention this requires SDL 2 to work.

Undefined reference is indication that you are not linking correct libraries.

I see that you want to make this work on linux - aside from SDL 2 see this http://www.bitsphere.co.za/gameDev/openGL/vsync.php

Dang. I would like as much system compatibility as possible, and from what I have read, SDL 1.2 is supported the most, so I will need to use it. Thank you for the link! The information on the page seems to be helpful. Looks like I will have to settle with using extensions. Thanks again! :)

Update: I implemented the code on the page you mentioned and it prints that there is no V-Sync to the console window. When I leave swapInterval(1);, there is a loop of it saying that there is no V-Sync. When I comment it out, the rendering window actually renders, but there is no V-Sync.


dpy = XOpenDisplay(NULL);
screen_num = DefaultScreen(dpy);

The above code is how I am initializing the variables needed by the code you linked to. Hopefully what is going wrong is I should not be using "NULL" where I am, but I could not find anything else to put there. Thanks again!

Do you suggest using SDL 1.3.0?

It will be a good start smile.png As proanim@ mentioned its now 2.0 and should be cloned/compiled from mercurial repo.

Hopefully 2.0 will be considered the latest stable release here soon. What am I supposed to do about people on systems that only support SDL 1.2? Is SDL 2.0 less cross-platform? So many questions! Thanks for your responses, everyone!

My understanding is that SDL 2.0 was supposed to be SDL 1.3, but they renamed it to 2.0 for some reason. Older versions used OpenGL to some extent and now SDL 2.0 is made to support newer OpenGL 3 and up context. So it is actually major change from the previous, but then again SDL 1.2 supported pc that are now very very old (single core cpu's and such). Is it less cross-platform? It isn't supposed to be.

This topic is closed to new replies.

Advertisement