Sign in to follow this  
zealkaiser

How to use glut/glfw callbacks in classes

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this