Hi! I’m trying to set hints in my options screen. Stucked in vsync.
Core::Core() : frameTime(0), MIN_FRAME_TIME(3.333333333333333f), w(0), h(0)
{
window.Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO);
window.createWindow("Platformer", Config::SCREEN_WIDTH, Config::SCREEN_HEIGHT,
SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
renderer = SDL_CreateRenderer(window.getWindow(), -1, SDL_RENDERER_ACCELERATED);
event = new SDL_Event;
Initialize();
}
void Core::MainLoop()
{
lFPSTime = SDL_GetTicks();
while (!quit && event->type != SDL_QUIT)
{
//tried here
//SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1");
SDL_GetWindowSize(window.getWindow(), &w, &h);
frameTime = SDL_GetTicks();
SDL_PollEvent(event);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
std::cout << "FPS: " + std::to_string(iNumOfFPS) << std::endl;
if (SDL_GetTicks() - 1000 >= lFPSTime)
{
lFPSTime = SDL_GetTicks();
iNumOfFPS = iFPS;
iFPS = 0;
}
++iFPS;
//tried here
SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1");
Input();
Update();
Draw();
SDL_RenderPresent(renderer);
if (SDL_GetTicks() - frameTime < MIN_FRAME_TIME)
{
SDL_Delay(MIN_FRAME_TIME - (SDL_GetTicks() - frameTime));
}
SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1");
}
SDL_FreeCursor(ScreenManager::GetInstance().GetCursor());
}
I know that this fps timer isn’t so good. Just want to test out hints.
So what this code doing. MIN_FRAME_TIME is set to 3.3333333 so it means it’s going to be ~300 fps. In mainLoop I set vsync to 1, so it should set fps to 144, because my monitor is 144hz. Unfortunately timer still shows 300 FPS. The only way to set vsync is set
renderer = SDL_CreateRenderer(window.getWindow(), -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
but this way I cannot set it via options screen.