Hello i am developing a great game in SDL2 and i have added a FPS regulator to make it smooth on every machine , but then i have created a sample program to ouput fps (not regulate , just output to see the power of current machine its running on ) and i have test it on 2 different computers , one is 12 years old , and the second is new , the old has like 512 mb ram and the new one has 16gb and both of them showed me that this sample code is running under 62,5 FPS , i am pretty sure that im not calculating my fps correctly , whats wrong please ?
#include<SDL.h>
#include<iostream>
#include<sstream>
#include<string>
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *window = nullptr;
Uint32 startclock = 0;
Uint32 deltaclock = 0;
Uint32 currentFPS = 0;
window = SDL_CreateWindow("Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN);
SDL_Renderer *renderTarget = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
SDL_Texture *texture = NULL;
bool isRunning = true;
SDL_Event ev;
while (isRunning)
{
startclock = SDL_GetTicks();
while (SDL_PollEvent(&ev) != 0)
{
if (ev.type == SDL_QUIT)
isRunning = false;
}
SDL_RenderClear(renderTarget);
SDL_RenderCopy(renderTarget, texture, NULL, NULL);
SDL_RenderPresent(renderTarget);
deltaclock = SDL_GetTicks() - startclock;
startclock = SDL_GetTicks();
currentFPS = 1000.0f / deltaclock;
std::string x;
std::stringstream ss;
ss << currentFPS;
ss >> x;
x = "FPS: " + x;
SDL_SetWindowTitle(window, x.c_str());
}
return 0;
}