|
@@ -42,6 +42,9 @@ static int rot_x = 0, rot_y = 0, rot_z = 0;
|
|
|
// Do redraw?
|
|
|
static int do_redraw = 1;
|
|
|
|
|
|
+// Keep running?
|
|
|
+static GLboolean running = GL_TRUE;
|
|
|
+
|
|
|
|
|
|
//========================================================================
|
|
|
// Draw a solid torus (use a display list for the model)
|
|
@@ -435,6 +438,17 @@ static void mouseButtonFun(GLFWwindow window, int button, int action)
|
|
|
}
|
|
|
|
|
|
|
|
|
+//========================================================================
|
|
|
+// Window close callback function
|
|
|
+//========================================================================
|
|
|
+
|
|
|
+static int windowCloseFun(GLFWwindow window)
|
|
|
+{
|
|
|
+ running = GL_FALSE;
|
|
|
+ return GL_TRUE;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
//========================================================================
|
|
|
// main
|
|
|
//========================================================================
|
|
@@ -470,6 +484,7 @@ int main(void)
|
|
|
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
|
|
|
|
|
|
// Set callback functions
|
|
|
+ glfwSetWindowCloseCallback(windowCloseFun);
|
|
|
glfwSetWindowSizeCallback(windowSizeFun);
|
|
|
glfwSetWindowRefreshCallback(windowRefreshFun);
|
|
|
glfwSetCursorPosCallback(cursorPosFun);
|
|
@@ -493,9 +508,11 @@ int main(void)
|
|
|
// Wait for new events
|
|
|
glfwWaitEvents();
|
|
|
|
|
|
+ if (glfwGetKey(window, GLFW_KEY_ESCAPE))
|
|
|
+ running = GL_FALSE;
|
|
|
+
|
|
|
} // Check if the ESC key was pressed or the window was closed
|
|
|
- while (glfwIsWindow(window) &&
|
|
|
- glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS);
|
|
|
+ while (running);
|
|
|
|
|
|
// Close OpenGL window and terminate GLFW
|
|
|
glfwTerminate();
|