Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: What's wrong with frame time in SFML 2?  (Read 6651 times)

0 Members and 1 Guest are viewing this topic.

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
What's wrong with frame time in SFML 2?
« 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.

Code: [Select]
#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:

Code: [Select]
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.

bananu7

  • Newbie
  • *
  • Posts: 25
    • View Profile
What's wrong with frame time in SFML 2?
« Reply #1 on: October 15, 2011, 12:48:08 am »
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:
Code: [Select]
static int FrameCounter = 0;
if (FrameCounter > 60)
{
   /*set clear color to red */
   FrameCounter = 0;
}
else
{
 /* set clear color to blue */
 FrameCounter++;
}
window.Clear();

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
What's wrong with frame time in SFML 2?
« Reply #2 on: October 15, 2011, 01:23:41 am »
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.

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
What's wrong with frame time in SFML 2?
« Reply #3 on: October 15, 2011, 05:20:16 am »
Frametime is measured in milliseconds, so that's correct. Also, which way are the rectangles rotating when given a positive angle? Clockwise or counterclockwise?
I use the latest build of SFML2

bananu7

  • Newbie
  • *
  • Posts: 25
    • View Profile
What's wrong with frame time in SFML 2?
« Reply #4 on: October 15, 2011, 10:53:34 am »
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.

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
What's wrong with frame time in SFML 2?
« Reply #5 on: October 15, 2011, 12:02:35 pm »
Quote from: "OniLink10"
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.
Quote from: "bananu7"

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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
What's wrong with frame time in SFML 2?
« Reply #6 on: October 15, 2011, 02:33:25 pm »
Quote
Does SFML2 manage the orientation differently according to SFML1.6?

Yes ;)
Laurent Gomila - SFML developer

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
What's wrong with frame time in SFML 2?
« Reply #7 on: October 16, 2011, 02:00:06 pm »
Thanks all of you, all my doubts solved :)

sbroadfoot90

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
What's wrong with frame time in SFML 2?
« Reply #8 on: October 16, 2011, 11:13:53 pm »
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

Code: [Select]
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 :)

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
What's wrong with frame time in SFML 2?
« Reply #9 on: October 16, 2011, 11:44:18 pm »
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 ;)

 

anything