Sign in to follow this  

GLFW Callback Trouble

Recommended Posts

I have a class that includes all my GLFW callback functions, but I get an error when I try to set the callbacks. The error is: "argument of type `void (dave::gui::Root::)(int, int)' does not match `void*'" It seems that GLFW callbacks must be in the global namespace. Is there any way around this so that I don't have to have these callbacks in the global namespace? The first solution I came up with was to have the callbacks in the global namespace, and then making the original callbacks in my class public, and then calling those from the global callback functions. This is very messy to me and I'd like to avoid this "solution" if possible. Any ideas are appreciated. Thanks.

Share this post

Link to post
Share on other sites
They do not need to be in the global namespace, the compiler just needs to know their location on compile time. That means they will have to be static functions within the class, usually callbacks over a void* to pass the class in, like this.

class MyClass
static void myCallback(void*);

void myCallback();

void MyClass::myCallback(void* data)
MyClass* my_class = reinterpret_cast<MyClas*>(data);

I do not really know what GLFW offers though.

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