如何对用 C 编写的 GLUT 程序设置关闭操作? (如左上角红色按钮即可工作)
我正在 XCode 4.2 中使用 GLUT 和 C 编写一个非常简单的程序。
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow("GLUT Program");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glutMainLoop();
return EXIT_SUCCESS;
}
当窗口打开时,我无法通过左上角的红色按钮(Mac)关闭它,因为它呈灰色。如果我所做的任何 Java 编程都是一个模型,那么应该有一些函数可以设置关闭操作,以便红色退出按钮起作用。我似乎也找不到最新版本的 GLUT 的文档。每当我谷歌它时,我似乎都会得到OpenGL文档,这让我对两者之间的关系更加困惑(我认为GLUT是与OpenGL交互的跨平台接口)。
I'm writing a really simple program using GLUT and C in XCode 4.2.
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow("GLUT Program");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glutMainLoop();
return EXIT_SUCCESS;
}
When the window opens up, I can't close it via the red button in the top left corner (Mac) because it is grayed out. If any Java programming I've done is a model, there should be some function that sets the close operation so that the red exit button works. I also can't seem to find the documentation for the most recent version of GLUT. Whenever I google it I seem to get OpenGL documentation, which makes me a little more confused then I was on the relationship between the two (I thought GLUT was a cross-platform interface to interact with OpenGL).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 Mac OS 上,无法关闭窗口,必须退出应用程序 (来源 此处)。
On Mac OS, the window cannot be closed and the application has to be quit instead (sources here).
在 OS X 上使用 python 的 GLUT 绑定,我发现将事件处理程序传递给 glutWMCloseFunc 足以给出一个操作(显然,这已被弃用,有利于 glutCloseFunc,但在我的版本中则不然)。
Using the GLUT bindings for python on OS X, I find passing an event handler to glutWMCloseFunc is enough to give an action (apparently this is deprecated in favour of glutCloseFunc, but not with my version).
如果您想使用 Mac 的窗口系统来编写类似 Mac 的本机应用程序(并且您应该 - 您的用户会感谢您!),您应该使用 NSOpenGLView 而不是 GLUT。 这里有一些很好的示例代码。
If you want to use the Mac's windowing system to write a native Mac-like application (and you should - your users will thank you!), you should be using NSOpenGLView instead of GLUT. There's some good sample code here.
好吧,我现在遇到了这个问题,我用来
退出进程,它有效。
well, i encountered this problem now, and i use
to quit the process, it works.
添加关闭按钮的处理程序,它将出现:
Add a handler for the close button and it will appear: