0

I've got timer issue in GLUT.

glutGet(GLUT_ELAPSED_TIME) only get time with sec accuracy (1000, 2000, 3000...) and glutTimerFunc(...) works only when millis parameter is set greater than 1000.

I don't know exactly how GLUT measure time but I think there's something wrong with my system time setting.

How can I get time with millis accuracy in OpenGL?

HugoTeixeira
  • 4,674
  • 3
  • 22
  • 32
서강욱
  • 47
  • 1
  • 2
  • GPU: http://www.lighthouse3d.com/tutorials/opengl-timer-query/ CPU: https://en.cppreference.com/w/cpp/chrono – Ripi2 Sep 21 '18 at 19:29
  • 1
    [`std::chrono::high_resolution_clock::now()`](https://en.cppreference.com/w/cpp/chrono/high_resolution_clock/now)? – genpfault Sep 21 '18 at 19:32

1 Answers1

0

As already mentioned in the comments above, you could use more reliable C++ date and time utilities like the std::chrono library. Here is a simple example:

#include <iostream>
#include <chrono>

int main()
{
    const auto start = std::chrono::high_resolution_clock::now();

    // do something...

    const auto end = std::chrono::high_resolution_clock::now();

    std::cout << "Took " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << " ms\n";

    return 0;
}
HugoTeixeira
  • 4,674
  • 3
  • 22
  • 32
  • Thank you for thr answer. Actually, I avoided this problem by using clock() in ctime instead of glutGet, but when Im trying to use glutTimerFunc, I have to rely on glut's time. – 서강욱 Sep 22 '18 at 02:58