Jump to content

  • Log In with Google      Sign In   
  • Create Account

pixeltasim

Member Since 01 May 2012
Offline Last Active Oct 05 2014 12:27 PM

Topics I've Started

Finding out FPS

26 February 2013 - 07:40 PM

I just started working with SDL and with some help from the internet got deWitter's game loop working, but I want to find out what my fps is. I'm not exactly sure how to go about doing this, and I haven't really understood any answer I have found on the internet. Any answers would be appreciated. 

#include <SDL.h>

int main( int argc, char *argv[] )
{
const int TICKS_PER_SECOND = 25;
const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
const int MAX_FRAMESKIP = 5;

float interpolation;
int loops;
int fps;

SDL_Event event;
SDL_Surface *screen = NULL;
screen = SDL_SetVideoMode( 640, 480, 32, SDL_HWSURFACE);

SDL_Surface* bmp = SDL_LoadBMP("cb.bmp");
SDL_Rect source;
source.x = 0;
source.y = 0;
source.h = 150;
source.w = 120;

SDL_Rect dest;
dest.x = 120;
dest.y = 120;
dest.h = 150;
dest.w = 120;

bool running = true;
unsigned int next_game_tick = SDL_GetTicks();

while ( running )
{

while( SDL_PollEvent( &event ) )
{
if ( event.type == SDL_QUIT )
running = false;
}
if (event.type == SDL_KEYDOWN)
         {
            SDLKey keyPressed = event.key.keysym.sym;

            switch (keyPressed)
            {
               case SDLK_ESCAPE:
                  running = false;
                  break;
            }
         }


loops = 0;
while( SDL_GetTicks() > next_game_tick && loops < MAX_FRAMESKIP )
{


// update_game();

next_game_tick += SKIP_TICKS;
loops ++;
}

interpolation = float( SDL_GetTicks() + SKIP_TICKS - next_game_tick ) / float( SKIP_TICKS );

// display_game( interpolation );
SDL_BlitSurface(bmp,&source,screen,&dest);
SDL_Flip(screen);

}

return 0;
}

 

 


PARTNERS