GLFW: window & contextGLFW 3.0
glfwSetWindowShouldClose
Raises (or lowers) the window's close flag, the same flag the close button raises.
Signature
void glfwSetWindowShouldClose(GLFWwindow* window, int value);
How it works
Use GLFW_TRUE to end the main loop from your own code, such as an Esc key or a "Quit" menu item. Use GLFW_FALSE to cancel a close the user asked for, for example after "you have unsaved changes".
Parameters
windowGLFWwindow*
The window whose flag to change.
valueint
GLFW_TRUE to ask for closing, GLFW_FALSE to cancel it.
Tips & pitfalls
It does not close anything by itself: the loop still has to see the flag and exit.
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 if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
3 glfwSetWindowShouldClose(w, GLFW_TRUE);
4}