2011-11-21 22 views
0
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值?

+1

沒看過代碼,但是您是否檢查過您的驅動程序是否啓用了vsync? (注意:不要編寫代碼來限制幀速率,你可以使用vsync!) – Shahbaz

回答

4

60 FPS_ = 16.7ms/f。修復參數SDL_Delay

順便說一句:爲了將來,養成使用ms/f而不是fps的習慣 - 這項措施實際上要容易得多。

BTW2:60FPS與SDL?您將需要硬件加速,我擔心SDL本身不會爲您提供硬件加速。也許考慮SDL + OpenGL或SFML。

0

這可能是因爲你的系統無法跟上60 fps。只是因爲你告訴它並不意味着它將能夠。

+0

演示程序應該能夠跟上60FPS。 –

相關問題