Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 01 May 2012
Offline Last Active Aug 22 2016 01:26 PM

Posts I've Made

In Topic: Finding out FPS

28 February 2013 - 05:19 AM

Thank You! It was part of the problem actually, I was assigned %u when I should have been doing %f. I've switched my variables over to uint32 though, because that's what SDL_GetTicks() returns in. I've got my FPS working now with a modified timer and Min/Avg/Max framerate system going. 

In Topic: Finding out FPS

27 February 2013 - 04:16 PM

Alright, so I figured out how to display FPS properly, but I am now having an issue with SDL_GetTicks(), whenever I try to assign a variable to it, the variable's value remains zero, while when I check SDL_GetTicks() directly, it works fine. 

float Timer::timeSinceCreation()//calling this method returns zero as well
   return SDL_GetTicks(); 

float Timer::timeSinceLastFrame()
   float thisTime = SDL_GetTicks();//thistime is always zero
   float deltaTime = thisTime - m_timeOfLastCall;//, thus every other value remains zero
   m_timeOfLastCall = thisTime;
   printf("%u ms \n",thisTime );
   return deltaTime;


The program ran fine once, but then it stopped working. 


Just realized, this seems to be part of a larger problem in this class, all of the variables don't get assigned, so when I changed deltaTime to 5, it stayed at zero.

In Topic: Finding out FPS

27 February 2013 - 05:43 AM

I followed the tutorial and used their timer class, but I have an absolutely massive fps, and I'm not sure if that is correct.

#include <SDL.h>
#include "Timer.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 frame;
Timer fps;
Timer update;

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

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;

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 );
    int fpsnum = frame/(fps.get_ticks()/1000.f);
    printf("Rendering at %u frames per second\n", fpsnum);


return 0;

Standard output:
Rendering at 2683765 frames per second
Rendering at 895185 frames per second
Rendering at 537183 frames per second
Rendering at 383724 frames per second
Rendering at 298462 frames per second
Rendering at 244201 frames per second
Rendering at 223834 frames per second
Should that be normal?

In Topic: Finding out FPS

27 February 2013 - 05:23 AM

Alright, thank you! I will try that out. 

In Topic: Impotant! Books to start learning video game programming ! I need it...

16 November 2012 - 09:36 AM

I am not going to hold your age against you, but I am going to tell you what I tell everybody who has started getting into game development. There is this thing called Google. I taught myself how to program without any books at the same age as you. The internet is such a great thing, there are so many resources out there (this site included) that will pretty much tell you everything you will need to know to make a game. Why do you need it so fast? Unless you are doing it for a project, patience will help you out here. You can't just learn how to program in a week, or a month, it took me two years to learn enough of programming to make anything that wasn't a clone of something else and was remotely fun. If you are set in looking for books, I would highly suggest a book about C++, not game programming. Game programming will not teach you the ins and outs of a language, you will learn a lot, but I suggest learning the language before learning game programming. Best of luck with your future endeavors! Also, if you do persist, you will find the immensely rewarding and awesome world of programming, which is amazing in its own right.