Hello,
I am having trouble displaying the FPS on my screen correctley. It just shows FPS with numbers going across the screen. I’ll post my code and tell where the problem is occuring. The code runs fine.
Code:
while(GameRunning)
{
iThisTime = SDL_GetTicks();
fDeltaTime = (float)(iThisTime - iLastTime) / 1000;
iLastTime = iThisTime;
szFPS << "FPS:" << fDeltaTime;
FPS = TTF_RenderText_Solid(Font,szFPS.str().c_str(), textColor);
FPSRect.x = 1;
FPSRect.y = 1;
FPSRect.w = 0;
FPSRect.h = 0;
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
GameRunning = false;
}
if(event.type == SDL_KEYDOWN)
{
keyPressed = event.key.keysym.sym;
keysHeld[event.key.keysym.sym] = true;
if(keyPressed == SDLK_ESCAPE)
{
GameRunning = false;
}
}
if(event.type == SDL_KEYUP)
{
keyReleased = event.key.keysym.sym;
keysHeld[event.key.keysym.sym] = false;
}
}
if(SDL_Flip(Screen) == -1)
{
exit(1);
}
SDL_BlitSurface(FPS,NULL,Screen,&FPSRect);
}
}
Where I have the “szFPS” is where it seems to have the random numbers going across the screen. I need to fix this so it shows only the current FPS in the top
left corner of the screen.