I have an an OSX OpenGL app I\'m trying to modify. When I create the app a whole bunch of initialisation functions are called -- including methods where I can specify my own
In freeglut if you call this:
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION)
Prior to entering the main loop, then when the window closes the main loop function will return and you can do your cleanup.
It's worth noting that at that stage the GL context has already been destroyed so you can't perform any GL operations.