Skip to main content
GameDev.net gamedev.net
🔒 Locked

How to use glut/glfw callbacks in classes

Started by zealkaiser Jun 7, 2011 at 5:24 AM 0 replies 2.7k views
Original Post
zealkaiser
zealkaiser
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.
haegarr
haegarr
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.