如何对用 C 编写的 GLUT 程序设置关闭操作? (如左上角红色按钮即可工作)

发布于 2024-12-23 18:33:02 字数 592 浏览 2 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

甜`诱少女 2024-12-30 18:33:02

在 Mac OS 上,无法关闭窗口,必须退出应用程序 (来源 此处)。

On Mac OS, the window cannot be closed and the application has to be quit instead (sources here).

梦冥 2024-12-30 18:33:02

在 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).

执手闯天涯 2024-12-30 18:33:02

如果您想使用 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.

攒一口袋星星 2024-12-30 18:33:02

好吧,我现在遇到了这个问题,我用来

Command + Q

退出进程,它有效。

well, i encountered this problem now, and i use

Command + Q

to quit the process, it works.

遮了一弯 2024-12-30 18:33:02

添加关闭按钮的处理程序,它将出现:

void winCloseFunc()
{
    glutDestroyWindow(g_windowId);
    exit(0);
}

int main( ... )
{
    ...
    glutWMCloseFunc(winCloseFunc);
    ...
}

Add a handler for the close button and it will appear:

void winCloseFunc()
{
    glutDestroyWindow(g_windowId);
    exit(0);
}

int main( ... )
{
    ...
    glutWMCloseFunc(winCloseFunc);
    ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文