Trouble with vsync using glut in OpenGL

倾然丶 夕夏残阳落幕 提交于 2019-12-04 18:23:45

Ok - between the great help I've received here, and my own hours of research and messing around with it I've discovered a few things, including a solution that works for me (in case others come across this problem).

Firstly, I was using freeGLUT, I converted my code to GLFW and the result was the same, so this was NOT an API issue, don't waste your time like I did!

In my program at least, using wglSwapIntervalEXT(1) DOES NOT stop vertical tearing, and this was what led to it being such a headache to solve.

With my NVIDIA driver set to VSYNC = ON I was still getting tearing (because this is equivalent to SwapInterval(1) which doesn't help) - but it was set correctly, the driver was doing what it should have been I just didn't know it because I was still getting tearing.

So I set my NVIDIA driver to VSYNC = 'Application preference' and used wglSwapIntervalEXT(60) instead of 1 which I had always been using, and found that this was actually working because it was giving me a refresh rate of about 1Hz.

I don't know why wglSwapIntervalEXT(1) doesn't Vsync my screen, but wglSwapIntervalEXT(2) has the desired effect, though obviously I'm now rendering every other frame which is inefficient.

I found that with VSYNC disabled glFinish DOES NOT help with tearing, but with it enabled it does (If anyone can explain why that would be great).

So in summary, with wglSwapIntervalEXT(1) set and glFinish() enabled I no longer have tearing, but I don't understand still why.

Here's some performance stats in my app (deliberately loaded to have FPS's below 60):

  • wglSwapIntervalEXT(0) = Tearing = 58 FPS
  • wglSwapIntervalEXT(1) = Tearing = 58 FPS
  • wglSwapIntervalEXT(2) = No tearing = 30 FPS
  • wglSwapIntervalEXT(1) + glFinish = No Tearing = 52 FPS

I hope this helps someone in the future. Thanks for all your help.

i am also having problem with vsync and freeglut. previously i used glut, and i was able to selectivly enable vsync for multiple GLUT-windows.

Now with freeglut, it seems like that the wglSwapIntervalEXT() has no effect. What has effect is the global vsync option in the NVIDIA control panel. If I enable the vsync there, i have vsync in both of my freeglut windows, and if i disable i dont have. It does not matter what i set specificly for my application (in the nvidia control panel). Also this confirms what i observe:

if(wglSwapIntervalEXT(0)) 
printf("VSYNC set\n");
int swap=wglGetSwapIntervalEXT();
printf("Control window vsync: %i\n",swap);

the value of swap is always the value that is set in the NVIDIA control panel. Does not matter what is want to set with wglSwapIntervalEXT().

Otherwise here you can read what the GLFinish() is good for: http://www.opengl.org/wiki/Swap_Interval

I use it because i need to know when my monitor is updated, so i can synchronously execute tasks after that (capture with a camera something).

Mike D

As described in this question here, no "true" VSync exists. Using GLFinish is the correct approach. This will cause your Card to finish processing everything it has been sent before continuing and rendering the next frame.

You should keep track of your FPS and the time to render a frame, you might find GLFinish is simply exposing another bottleneck in your code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!