while( quit == -1 )
{
// Did user quit?
while( SDL_PollEvent( &sdlEvent ) )
if( sdlEvent.type == SDL_QUIT )
quit = 1;
// Apply surfaces
ApplySurface(0, 0, background, screen);
// Flip the screen
if( SDL_Flip( screen ) == -1 )
return 1;
++numFrames;
sprintf( fpsbuff, "FPS: %.0f", (numFrames/(float)(SDL_GetTicks() - startTime))*1000);
SDL_WM_SetCaption(fpsbuff, NULL);
// Regulate FPS
currTime = SDL_GetTicks();
if( oldTime != 0 )
if( currTime - oldTime < 60 )
SDL_Delay(60 - (currTime-oldTime));
oldTime = currTime;
}
im trying to lock the FPS to 60, are some of my calculations wrong?
Any other smart way to lock the FPS to a value?
60 FPS ~= 16.7 ms/f. Fix the parameter in
SDL_Delay.BTW: For the future, get the habit of using ms/f instead of fps – this measure is actually much easier to work with.
BTW2: 60FPS with SDL? You are going to need hardware acceleration and I’m afraid SDL by itself won’t provide it for you. Consider SDL+OpenGL or SFML perhaps.