0
\$\begingroup\$

I have an SDL/OpenGL program which creates a rendering context with PRESENTVSYNC enabled, then enters an animation loop which calls SDL_GL_SwapWindow each time around. On my own machine, the animation works fine at a sensible speed, but on my office machine it runs with no vsync delay at all resulting in the animation running at breakneck speed and tearing all over the frame. Adding a sleep() to the animation loop slows it down sensibly.

I know that I can use SDL_GL_GetSwapInterval to see if swapping is being synchronized or not, but is there a way to find out what the actual refresh rate of the screen is in order to know how long or short the sleep should be?

\$\endgroup\$
1
\$\begingroup\$

You need to use SDL_GL_SetSwapInterval. Pass in 1 to enable VSYNC.

SDL_PRESENT_VSYNC is a SDL_Renderer flag and has no effect on pure OpenGL rendering. It only affects rendering performed using the SDL's rendering module.

\$\endgroup\$
0
\$\begingroup\$

You can use SDL_GetDisplayMode or SDL_GetCurrentDisplayMode, which will copy data into an SDL_DisplayMode you pass it, including the screen's refresh rate.

https://wiki.libsdl.org/SDL_GetDisplayMode

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.