glfwMakeContextCurrent
Makes this window's OpenGL context the one gl* calls on this thread talk to.
Signature
void glfwMakeContextCurrent(GLFWwindow* window);
How it works
OpenGL functions take no window parameter: they act on the context that is "current" on the calling thread. After glfwCreateWindow no context is current yet, so this call comes next, before the glad loader and before any gl* call.
A context can be current on only one thread at a time. With several windows, switch contexts with this call before drawing into each one.
Parameters
The window whose context becomes current, or NULL to leave this thread with no context.
Tips & pitfalls
glfwSwapIntervalandglfwGetProcAddressact on the current context, so they only work after this call.To render from a worker thread, make the context current THERE (and not current on the main thread).
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.
- GLFW_NO_WINDOW_CONTEXT
- The window was created with GLFW_CLIENT_API set to GLFW_NO_API, so it has no context.
- GLFW_PLATFORM_ERROR
- The operating system or window system reported a failure; the description says which.
Example
1GLFWwindow* window = glfwCreateWindow(800, 600, "App", nullptr, nullptr);
2glfwMakeContextCurrent(window); // gl* now talks to this window
3glfwSwapInterval(1); // needs a current context