Saturday, November 3, 2018

c++ - How to calculate delta time with SDL?



I have heard that you can calculate delta time with two functions called SDL_GetPerformanceCounter and SDL_GetPerformanceFrequency. I'm not sure how they work completely, but I heard it is a bit similar to using SDL_GetTicks()


    Uint64 NOW, LAST;
double deltaTime = 0;

while (somebool)
{
LAST = SDL_GetPerformanceCounter();
NOW = SDL_GetPerformanceCounter();
LAST = NOW;


deltaTime = (NOW - LAST) / (double)SDL_GetPerformanceFrequency();

/**Rendering**/
}

I have this code but whenever I print out deltaTime or try to use it it always equals some really random and insane numbers. Is this correct?




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...