Skip to main content
3 of 5
added 1 character in body
James McLeod
  • 7.6k
  • 4
  • 24
  • 35

It's not quiet zero-overhead, but you can use the GLFWwindow User Pointer Property to make a relatively clean solution, I think (caveat: my C++ is a little rusty, and I am not familiar with the GLFW library).

In your Window constructor,

Window(...) {
        // ...
        glfwSetWindowUserPointer(mHandle, static_cast<void *>(this));
        glfwSetWindowCloseCallback(mHandle, Window::onCloseWrapper);
};

And then define onCloseWrapper (in the Window class) as:

static void onCloseWrapper(GLFWwindow *wHandle) {
        Window *w = static_cast<Window>(glfwGetWindowUserPointer(wHandle));
        w.onClose()
}
James McLeod
  • 7.6k
  • 4
  • 24
  • 35