Saturday, October 1, 2022
HomeGame Developmentc++ - Odd SDL VSYNC behaviour when monitor is ready to 50...

c++ – Odd SDL VSYNC behaviour when monitor is ready to 50 Hz


I’m observing unusual behaviour with VSync in SDL. I’ve this code:

int fundamental()
{
   SDL_Init(SDL_INIT_EVERYTHING);
   SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");

   auto window = SDL_CreateWindow("window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1200, 480, 0);
   auto renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

   whereas (true)
   {
      static auto begin = std::chrono::high_resolution_clock::now();
      auto finish = std::chrono::high_resolution_clock::now();
      auto elapsed_us = std::chrono::duration_cast<std::chrono::microseconds>(finish - begin).depend();
      begin = finish;

      std::cout << elapsed_us << std::endl;

      SDL_RenderPresent(renderer);
   }
}

So after I set my monitor to 60 Hz I get output as anticipated:

16673
17489
16011
16653
...

Which means every cycle’s length is round 16.667 ms. Similar after I set my monitor to 75 Hz it showscorrect values round 13.333 ms.

However after I set it to 50 Hz the output will probably be like this:

16845
3131
16702
3424
16772
3158
16825
3147
16872
3129
...

It looks as if the VSync sign comes twice per 20 ms interval. As soon as at round 16.667 ms mark and the second time at 20 ms.

How can this be defined?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments