Reputation: 1
I am using gettimeofday() function to calculate how long my code takes. I am also counting how many frames have been displayed. The count shows that my code has done 6408 frames in 10 seconds - but on the screen I am only seeing about 8 fps. Here is my code:
SDL_AppResult SDL_AppIterate(void *appstate)
{
struct timeval stop, start;
SDL_RenderClear(renderer);
gettimeofday(&start, NULL);
for( int i=0; i<1000; i++)
{
float x = rand() % 3000;
float y = rand() % 2000;
SDL_FRect srcRect = {200,200,100,100};
SDL_FRect destRect = {x,y,100,100};
SDL_RenderTexture(renderer, fontTex, &srcRect, &destRect);
}
gettimeofday(&stop, NULL);
long cpu_time_used1 = (stop.tv_sec - start.tv_sec) * 1000000 + stop.tv_usec - start.tv_usec;
gettimeofday(&start, NULL);
SDL_RenderPresent(renderer);
gettimeofday(&stop, NULL);
long cpu_time_used2 = (stop.tv_sec - start.tv_sec) * 1000000 + stop.tv_usec - start.tv_usec;
char output[100];
snprintf(output, 50, "%d, %lu, %lu", count++, cpu_time_used1, cpu_time_used2);
SDL_Log(output);
return SDL_APP_CONTINUE;
}
The output of my code looks like this (at the end):
6406, 83, 1198
6407, 101, 1184
6408, 106, 1186
These timing numbers seem very low - is it possible that SDL3 is that quick? And why are I only seeing very low fps?
Upvotes: -1
Views: 63