Izman
Izman

Reputation: 419

Vertical Sync in iOS (SDL2 / OpenGL ES)

I'm using the iPhone simulator (iOS 8.2), and I'm having trouble enabling vertical sync using SDL2.

I'm trying to call:

if (SDL_GL_SetSwapInterval(-1) == -1)
    if (SDL_GL_SetSwapInterval(1) == -1)
        std::cout << "Failed to set Vertical Sync" << std::endl;

after creating the window and setting up the OpenGL ES 2 context to enable vertical sync, but it seems that both calls fail on iOS.

How can I enable vertical sync on an iOS platform using OpenGL ES 2 and SDL2?

In case that's not an option, is there an easy way to limit the FPS of an application to 60?

Upvotes: 0

Views: 688

Answers (1)

Martin G
Martin G

Reputation: 18109

This code limits FPS to desiredFPS.

while(!quit)
{
  frameStartTime = SDL_GetTicks();
  handleEvents();
  handleLogics();
  renderFrame();
  delayTime = (1000 / desiredFPS) - (SDL_GetTicks() - frameStartTime);
  SDL_Delay(delayTime);
}

Upvotes: 0

Related Questions