• Advertisement
Sign in to follow this  

How to use glut/glfw callbacks in classes

This topic is 2454 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello guys!
I am trying to make a Window class for glut or glfw .

I want it such that I just need to create the object of my window class all the stuff will done itself.
I am also successful in that but problem comes with callback functions.
If I set a member function of the class as callback function then I get error. But if I use any other function outside the class then it does not give any error.

Help me out guys. I want to make framework for very easy game development.

Share this post


Link to post
Share on other sites
Advertisement
Member functions of a class can be used as callback if and only if not only the function but also the object (instance of the function) is known to the caller. That further requires that the class was already known at compile time of the calling module. This can be solved for 3rd party software only by defining an interface (pure abstract class in C++, @protocol in Objective-C, ...) already in the caller's package, so that your software has to implement that interface.

However, e.g. GLUT is a C library and as such isn't aware of C++ (or other) classes at all. Hence you have to implement the routine as static, making it conformal to C. Whether this is a class routine or stand-alone plays no role. It has to obey the prescribed function signature, of course.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement