Jump to content
  • Advertisement
Sign in to follow this  
The_FuSiON

Problem with callback functions and GLFW

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

Hi, I'm using GLFW to write a little game. You can find the homepage of glfw at glfw.sf.net . Now I've come to the point where I need to get key input. With GLFW there are several ways of doing this. You can pass a callback function to GLFW and he calls then the function whenever a key was released or pressed. Now I've setup the ProcessInput() method of my GameEngine class as a static method and was following the prototype proposed in the documentation. But when passing the method to GLFW nothing happens. Everything compiles fine but somehow GLFW doesn't call the function when the user presses a key. I've been at this for a 5 hours now and I've been pulling my hair out about this. I hope somebody can help. Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
When you edit, there's also a checkbox to delete the post (if, say, you doubleposted).

You might want to show some [relevant] source code. People here can't "magically divine" what your problem is.

Share this post


Link to post
Share on other sites

// Here's how i define my method inside of my GameEngine class:
static void GLFWCALL ProcessInput(int key, int action);

// and the implementation:
void GameEngine::ProcessInput(int key, int action)
{
cout << "IT WORKED!!!!!" << endl;
}

// this is the function i call inside of the GameEngine constructor:

glfwSetKeyCallback(this->ProcessInput);



I think this should be the relevant code. If not I've uploaded all of the source to my webspace.
http://www.malwasandres.de/gameengine.zip

Sorry for not posting this earlier, I thought I've described my problem well enough.

Share this post


Link to post
Share on other sites
Nope, didn't work. I must be doing a stupid mistake somewhere. Or maybe GLFW has a bug somewhere?.

When thinking about this, I more and more come to the conclusion that a callback function is not the best way to do this. I mean the callback function in GLFW just returns keystate changes while the glfwGetKey() function returns the current state of the key. I think it should be enough to update the key states somewhere after a frame was rendered. I mean when a callback function is called it could be in the middle of the drawing of a frame and this could lead to problems.

Share this post


Link to post
Share on other sites
1) are you calling either glfwSwapBuffer or glfwPollEvents?
2) is a window open?
3) it might be that glfwSetKeyCallback requires a C function?
__a) try compiling glfw as a C++ library
__b) try making it a regular C function
__c) try making it a regular C function and make a pointer to it in your class-really have no idea on that one
__d) on the glfw forum,
https://sourceforge.net/forum/forum.php?forum_id=247562
someone mentioned functors, anyway there are a couple threads on this there

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!