Regulating Framerate

I have been playing around with the <ctime> library and tried to calculate fps
(frames per second). I combined it with SFML but the main thing I am working on is calculating fps with <ctime>.

Is this the right way to calculate fps?
ans
How would I regulate the fps to not go too high?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  #include <ctime>
#include <iostream>

using namespace std;

int main()
{
    sf::Window window(sf::VideoMode(800, 600), "My window");
    clock_t ela;
    float frames = 0;
    float fps;

    while(window.isOpen()){
      ela = clock();
      sf::Event event;
              while (window.pollEvent(event))
              {


                  // "close requested" event: we close the window
                  if (event.type == sf::Event::Closed){
                  	window.close();

                }


              }
      ela = clock() - ela;
      fps = frames / clock() - ela;
      cout << fps << endl;
      frames += 1;
    }



    return 0;
}
closed account (zb0S216C)
This should help: http://en.sfml-dev.org/forums/index.php?topic=7018.msg46291#msg46291

Wazzak
Last edited on
Topic archived. No new replies allowed.