Hi there,
I have a problem with below code:
int Fps::getFps(sf::Time elapsedTime)
{
static int frameCounter = 0;
static float frameTime = 0.0f;
static int fps = 0;
frameCounter++;
frameTime += elapsedTime.asSeconds();
if(frameTime >= 1.0f)
{
fps = frameCounter;
frameCounter = 0;
frameTime -= 1.0f;
}
return fps;
}
void Game::processRenderThread()
{
if(renderWindow)
{
renderWindow->setActive(true);
sf::Clock clock;
while(renderWindow->isOpen())
{
sf::Time elapsedTime = clock.getElapsedTime();
//clear
//draw something
//update and draw FPS
//display
sf::sleep(sf::milliseconds(1));
clock.restart();
}
}
}
If i use this code, the FPS is always equal 0
But, if i change:
sf::Time elapsedTime = clock.restart();
//clear
//draw something
//update and draw FPS
//display
sf::sleep(sf::milliseconds(1));
It works!!!
Why???