GLFW: size, position & monitorsGLFW 3.0

glfwGetWindowUserPointer

Reads back the pointer stored with glfwSetWindowUserPointer.

Signature

void* glfwGetWindowUserPointer(GLFWwindow* window);

How it works

Used inside callbacks: they receive the window, ask it for the user pointer and cast it back to your type with static_cast.

Parameters

windowGLFWwindow*

The window to read from.

Return value

The stored pointer, or NULL if none was set.

Errors

When the call is invalid it does nothing and sets an error, which glGetError returns:

GLFW_NOT_INITIALIZED
Called before glfwInit or after glfwTerminate.

Example

example.cpp
1void onKey(GLFWwindow* w, int key, int, int action, int) {
2    auto* app = static_cast<App*>(glfwGetWindowUserPointer(w));
3    if (key == GLFW_KEY_P && action == GLFW_PRESS) app->paused = !app->paused;
4}
Official GLFW documentation