SFML community forums
Help => Window => Topic started by: Sutur on April 21, 2011, 10:35:51 pm
-
Hello folks!
Everytime I call sf::Window::GetFrameTime() it returns 0 which can't be true.
It was working a few days ago and I did not update/change any of the SFML files.
Even if I put sf::Sleep( 0.5 ) inside my applications main loop, it still returns 0.
Any idea how this could be caused?
I'm using Linux 64bit ( Ubuntu ) together with g++ and SFML 2.0.
-
Can you show your code?
-
This prints 0 over and over again:
#include <SFML/Window.hpp>
#include <iostream>
int main()
{
sf::Window window( sf::VideoMode( 800, 600 ), "" );
while( window.IsOpened() )
{
sf::Event event;
while( window.GetEvent( event ) )
if( event.Type == sf::Event::KeyPressed || event.Type == sf::Event::Closed )
window.Close();
sf::Sleep( 0.5 );
window.Display();
std::cout << window.GetFrameTime() << std::endl;
}
}
-
That's really weird. What if you directly use a sf::Clock instead?
-
Isn't it the correct behaviour if you call Display right before GetFrameTime ?
-
i've always noticed that the GetFrameTime works only (on my pc), if i call it before the draw
sf::Sleep( 0.5);
std::cout << window.GetFrameTime() << std::endl;
window.Display();
this should work...
-
GetFrameTime() can be called at any time, it returns the time from the last frame, not the current one. So the result doesn't depend on the moment when you call it.
-
std::cout << window.GetFrameTime() << std::endl;
window.Display();
It keeps telling me 0.
So does the following code:
#include <SFML/Window.hpp>
#include <iostream>
int main()
{
sf::Window window( sf::VideoMode( 800, 600 ), "" );
sf::Clock frameTimeCounter;
while( window.IsOpened() )
{
frameTimeCounter.Reset();
sf::Event event;
while( window.GetEvent( event ) )
if( event.Type == sf::Event::KeyPressed || event.Type == sf::Event::Closed )
window.Close();
sf::Sleep( 0.5 );
window.Display();
std::cout << frameTimeCounter.GetElapsedTime() << std::endl;
}
}
-
Try to replace Sleep(0.5) with an active loop that takes some time.
-
Try to replace Sleep(0.5) with an active loop that takes some time.
Does not change the behavior at all.
However, I managed to get it working by turning off Compiz.
Now the correct values are returned.
But I would really like it to work together with Compiz.
Please tell me if you can think of any solution.
Thanks in advance!
-
Does not change the behavior at all.
So your program runs actively for a significant amount of time, and the clock still returns 0 second elapsed??
However, I managed to get it working by turning off Compiz.
Compiz usually conflicts with OpenGL stuff, I don't know how it can mess up time measurement.
SFML simply uses the gettimeofday function to measure time, there's nothing weird behind the sf::Clock class.
-
So your program runs actively for a significant amount of time, and the clock still returns 0 second elapsed??
Yes, it did.
I switched to the latest SFML2 version( the one I was using before had been a few months old ) and it seems like it's now doing the job. I propably somehow messed up my previous SFML2 download.
Thanks for your help!