glutCloseFunc无需终止应用程序 [英] glutCloseFunc without terminating application

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

问题描述

我用glutCreateWindow创建了一个窗口,并使用glutMainLoop开始了一个循环.我想结束该循环并关闭窗口,所以我使用glutLeaveMainLoopglutCloseFunc销毁它.我的应用程序自动终止.

I have created a window with glutCreateWindow and started a loop using glutMainLoop. I want to end that loop and close the window so I use glutLeaveMainLoop and glutCloseFunc to destroy it. Automatically, my application terminates.

我希望该应用程序在窗口销毁后仍然存在.有可能吗?

I would like the application to persist after the window is destroyed. Is it possible?

据此链接我可以做到,但是我不知道如何.我正在使用 freeglut .

According to this link I can do it, however I don't know how. I'm using freeglut.

推荐答案

文档中glutCloseFunc() :

希望防止FreeGLUT在关闭窗口时退出的用户,应该考虑使用glutSetOption设置GLUT_ACTION_ON_WINDOW_CLOSE.

导致 glutSetOption()文档:

GLUT_ACTION_ON_WINDOW_CLOSE-控制当用户或系统关闭窗口时发生的情况:

GLUT_ACTION_ON_WINDOW_CLOSE - Controls what happens when a window is closed by the user or system:

  • GLUT_ACTION_EXIT将立即退出应用程序(默认情况下,GLUT的行为).
  • GLUT_ACTION_GLUTMAINLOOP_RETURNS将立即从主循环中返回.
  • GLUT_ACTION_CONTINUE_EXECUTION将继续执行其余窗口.
  • GLUT_ACTION_EXIT will immediately exit the application (default, GLUT's behavior).
  • GLUT_ACTION_GLUTMAINLOOP_RETURNS will immediately return from the main loop.
  • GLUT_ACTION_CONTINUE_EXECUTION will continue execution of remaining windows.

并且来自 glutLeaveMainLoop() :

glutLeaveMainLoop函数使freeglut停止事件循环.如果GLUT_ACTION_ON_WINDOW_CLOSE选项设置为GLUT_ACTION_GLUTMAINLOOP_RETURNSGLUT_ACTION_CONTINUE_EXECUTION,则控制将返回到名为glutMainLoop的函数;否则,控件将返回到该函数.否则应用程序将退出.

The glutLeaveMainLoop function causes freeglut to stop the event loop. If the GLUT_ACTION_ON_WINDOW_CLOSE option has been set to GLUT_ACTION_GLUTMAINLOOP_RETURNS or GLUT_ACTION_CONTINUE_EXECUTION, control will return to the function which called glutMainLoop; otherwise the application will exit.

将各个部分拼凑在一起:

Putting the pieces together:

#include <GL/freeglut.h>
#include <iostream>

void display()
{
    glClear( GL_COLOR_BUFFER_BIT );
    glutSwapBuffers();
}

int main( int argc, char** argv )
{
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
    glutCreateWindow( "GLUT" );
    glutDisplayFunc( display );
    glutSetOption( GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS ); 
    std::cout << "Before glutMainLoop()!" << std::endl;
    glutMainLoop();
    std::cout << "Back in main()!" << std::endl;
    return 0;
}

这篇关于glutCloseFunc无需终止应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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