Jump to content
  • Advertisement
Sign in to follow this  
tstrimp

Unity glfwSetKeyCallback & Member Functions

This topic is 4596 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

I'm trying to set a member function as a callback for glfwSetKeyCallback and I'm not sure on how to go about it. I noticed someone else was having the same problem but their solution was to switch to a new framework! If anyone has had any success with this I would be greatly interested in hearing about it.

Share this post


Link to post
Share on other sites
Advertisement
The best thing I can think of is rather than use your class member function directly, you should just wrap it in a function that GLFW likes and procede from there. For example:

class MyInput
{
public:
static void processKeys(int key, int action)
{
...
}
};

...

void GLFWCALL KeyWrapper(int key, int action)
{
MyInput::processKeys(key, action);
}

...

glfwSetKeyCallback( KeyWrapper );

It's just a little more work, but it [should] get the job done fine. Note you can also not use a static function if you already have some global input class or one instance of it:

class MyInput
{
public:
void processKeys(int key, int action)
{
...
}
};
extern MyInput MyInputVar;
...

void GLFWCALL KeyWrapper(int key, int action)
{
MyInputVar.processKeys(key, action);
}

...

glfwSetKeyCallback( KeyWrapper );

So if you had muliple input objects or other classes that needed input as well so you do not dispatch from the input class itself, you can do so too. Good luck!

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!