1
\$\begingroup\$

I'm currently using Imgui for the GUI part of my OpenGL/C++ engine with the GLFW binding. The problem is though that this binding has encapsulated the input callbacks in a global .cpp file which makes it impossible to access for other classes. Now I could always use the regular routine to handle input without the callbacks like:

if(glfwGetKey(m_window, GLFW_KEY_A) == GLFW_PRESS)
   ...

but yet this won't give me the one-to-one mapping like the key callback provides as the conditional code is processed more than once. I have tried using static booleans without success to see if I could overcome the problem by setting the boolean to true when the key is pressed in the callback and then handling the outcome elsewhere. I also know that you can override callbacks with different ones but that would not make any sence in this case.

Does anyone know how to solve this problem?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

The problem is though that this binding has encapsulated the input callbacks in a global .cpp file which makes it impossible to access for other classes.

The imgui+GLFW backends have callback exposed in the imgui_impl_glfw_xxx.h file:

void ImGui_ImplGlfwGL3_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
void ImGui_ImplGlfwGL3_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
void ImGui_ImplGlfwGL3_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
void ImGui_ImplGlfwGL3_CharCallback(GLFWwindow* window, unsigned int c);

And when you call ImGui_ImplGlfwGL3_Init() you can set install_callbacks=true to install your own callback from where you can call the above functions if you need to.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Noticed there was actually a comment about this in the header file, but I must have ignored it. But it works as intended. Thanks, Omar! \$\endgroup\$
    – Riggs
    Nov 30, 2017 at 11:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .