退出OpenGL应用程序时清理 [英] Cleaning up when exiting an OpenGL app

查看:601
本文介绍了退出OpenGL应用程序时清理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个OSX OpenGL应用程序,我想修改。当我创建应用程序整个
的初始化函数被调用 - 包括方法,我可以指定自己的鼠标和键盘处理程序等。例如:

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 mouse and keyboard handlers etc. For example:

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(700, 700);
glutCreateWindow("Map Abstraction");
glutReshapeFunc(resizeWindow);
glutDisplayFunc(renderScene);
glutIdleFunc(renderScene);
glutMouseFunc(mousePressedButton);
glutMotionFunc(mouseMovedButton);
glutKeyboardFunc(keyPressed);

在某些时候,我将控制权交给glutMainLoop,我的应用程序运行。在运行的过程中,我创建了一大堆对象。我想清理这些。有没有什么办法我可以告诉GLUT在它退出之前调用一个清除方法?

At some point I pass control to glutMainLoop and my application runs. In the process of running I create a whole bunch of objects. I'd like to clean these up. Is there any way I can tell GLUT to call a cleanup method before it quits?

推荐答案

在freeglut如果你调用这个: / p>

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.

注意到在这个阶段GL上下文已经被销毁,所以你不能执行任何GL操作。

It's worth noting that at that stage the GL context has already been destroyed so you can't perform any GL operations.

这篇关于退出OpenGL应用程序时清理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆