Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Is there a way to use glutTimerFunc with modern C++ classes?

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2018
    Posts
    10

    Is there a way to use glutTimerFunc with modern C++ classes?

    Is there a way to use glutTimerFunc with modern C++ classes?

    Because I run into problems in using glutTimerFunc with classes that contain non-static members. The second argument of glutTimerFunc requires either static function or a function in an instance. Both of which seem to complicate class design principles a bit.

  2. #2
    Intern Contributor
    Join Date
    Oct 2014
    Posts
    63
    Quote Originally Posted by mavavilj View Post
    Is there a way to use glutTimerFunc with modern C++ classes?

    Because I run into problems in using glutTimerFunc with classes that contain non-static members. The second argument of glutTimerFunc requires either static function or a function in an instance. Both of which seem to complicate class design principles a bit.
    Is there any reason that you explicitly need glutTimerFunc? If not, just use the chrono lib of the STL to build your own timer function or class. If yes, I guess you can "smuggle in" everything you want by using lambdas:

    Code :
    MyClass myClass;
     
    glutTimerFunc(1000,[&](int)
                               {
                                    myClass.MyMemberFunction();
                               },0);

    Don't guarantee for code correction, since I didn't compile it, but lambda functions do work with glutTimerFunc.

    Greetings

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •