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;
}
即時嘗試鎖定FPS爲60,是我的一些計算錯誤?爲什麼FPS在試圖獲得60時顯示30?
任何其他聰明的方式來鎖定FPS值?
沒看過代碼,但是您是否檢查過您的驅動程序是否啓用了vsync? (注意:不要編寫代碼來限制幀速率,你可以使用vsync!) – Shahbaz