SFML community forums
Help => Window => Topic started by: julen26 on October 15, 2011, 12:34:59 am
-
Here I am again.
This time I'm trying to manage de framerate and frametime as well. I used the code pasted in the documentation of SFML 2, but something is wrong.
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <stdio.h>
int main()
{
// Create the main window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
window.EnableVerticalSync(true);
//window.SetFramerateLimit(60);
// Start the game loop
while (window.IsOpened())
{
// Process events
sf::Event event;
while (window.PollEvent(event))
{
// Close window : exit
if (event.Type == sf::Event::Closed)
window.Close();
}
// Clear screen
window.Clear();
// Update the window
window.Display();
printf("FPS: %f FRAMETIME: %f\n", (float)(1.f / window.GetFrameTime()), (float)(window.GetFrameTime()));
}
return EXIT_SUCCESS;
}
I use this simple program, but I get this in the output:
FPS: 0.58824 FRAMETIME: 17.000000
FPS: 0.62500 FRAMETIME: 16.000000
FPS: 0.58824 FRAMETIME: 17.000000
FPS: 0.58824 FRAMETIME: 17.000000
FPS: 0.62500 FRAMETIME: 16.000000
...
I get strange values instead of a framerate around 60 and its respective frametime. Using SFML 1.6 all goes well.
Hope that there is a reason. Thanks.
-
Could you try sending the output to a file instead of stdout?
Also, make sure that your framerate is actually what you expect, for example:
static int FrameCounter = 0;
if (FrameCounter > 60)
{
/*set clear color to red */
FrameCounter = 0;
}
else
{
/* set clear color to blue */
FrameCounter++;
}
window.Clear();
-
I get a the color change at a low rate. Anyway I realized that not all goes well using SFML 2.
For example, when I rorate a rectangle shape it rotates in the opposite direction givin the correct angle.
So I'm thinking that maybe I have not built it correctly.
-
Frametime is measured in milliseconds, so that's correct. Also, which way are the rectangles rotating when given a positive angle? Clockwise or counterclockwise?
-
The screen should flash red every second, when running 60 fps. If it's at lower rate, your code is running slower, so it may not be the case with sf::Timer - rather than that, something makes renderer to go too slow.
If @up is right and it's in fact in miliseconds, it's ok : 1/0.016 = 60.
-
Frametime is measured in milliseconds, so that's correct. Also, which way are the rectangles rotating when given a positive angle? Clockwise or counterclockwise?
Clockwise, I mean, when I set the orientation positive it turns clockwisse. Otherwise when I set it negative, it turns counterclockwise.
The screen should flash red every second, when running 60 fps. If it's at lower rate, your code is running slower, so it may not be the case with sf::Timer - rather than that, something makes renderer to go too slow.
If @up is right and it's in fact in miliseconds, it's ok : 1/0.016 = 60.
I've done it again, and yes, screen flashes every second (more or less). But, with GetFrameTime() method I get the same thing.
To be sure I've simulated a body's movement with euler integration, I activated the vsync and simulated the body with 0.016 of delta-time and it goes well. It means that the game is running at 60 fps. But again, I get those strange values.
Edit: Okay, I've solved FPS issue. But still remains the orientation problem. Does SFML2 manage the orientation differently according to SFML1.6?
-
Does SFML2 manage the orientation differently according to SFML1.6?
Yes ;)
-
Thanks all of you, all my doubts solved :)
-
I'll just add to the FPS thing. GetFrameTime returns time in milliseconds as an integer so converting it to a float isn't going to do anything
printf("FPS: %f FRAMETIME: %f\n", (float)(1.f / window.GetFrameTime()), (float)(window.GetFrameTime()));
that's why it's printing out with .0000000.
With 60 FPS, we expect 16.6666666... milliseconds per frame so that is consistent with your output values 16/17 :)
-
Yes, you're right. Thats why I ported it from SFML 1.6, where the result is in seconds. That was what I didn't know.
Thanks anyway ;)