View Full Version : glfwSwapInterval() and glfwSwapBuffer() Questions

04-19-2012, 11:17 AM
Its been about 4 days I've started learning OpenGL and I am using GLFW as my preferred Window and event handling library. I am having these flickering stripes on the screen in all of my test programs. I know it has something to do with the glfwSwapInterval() function which "selects the minimum number of monitor vertical retraces that should occur between two
buffer swaps." I've tried passing different values to it and the screen flickering slows down but doesn't stop. I noticed I had to hold the esc key longer to break out of the loop instead of just pressing it. Whats happening? lol. I really need some help to fix it otherwise I won't be able to continue learning the API. Have searched the web, found something called wglext.h which has a function(apparently it only works in windows) that is supposed to fix it,but couldn't use it. Please help me solve this problem one way or the other.

Stuart McDonald
04-24-2012, 05:50 AM
The swap interval is to do with v-sync i.e. so you can wait until the current frame has been drawn before you start drawing the next one.

With v-sync off you can get what's called 'tearing' where the top part of your screen shows the latest frame and the bottom the previous (with a 'tear' in the middle where they don't line up).

This might be the flickering stripes you mention, but you don't say what you are drawing (also you could be drawing to the front buffer instead of the back buffer). Have you got a simple example from the net working?. Can you draw a non moving single triangle without getting the stripes?

GLFW wraps the call to enable/disable vsync (wglSwapIntervalEXT on windows and glXSwapIntervalSGI on linux) so you don't need to worry about wglext.h. Set the value to 0 for off or 1 for on (can't think why you'd even set it to more than one).

One other thing, if vsync is on then you are locking the frame rate of your program to whatever the refresh rate of the monitor is e.g. 60hz, so if you are displaying FPS then it will show 60 (or whatever the rate is), assumming it's not running slower than that.

[EDIT] Also, what are you running on? I noticed that on a crappy laptop with integrated Intel graphics I can't enable v-sync. Presumably a driver problem, but I've never bothered to update to see if it fixed the problem.