Results 1 to 9 of 9

Thread: close program and exit

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2009
    Posts
    22

    close program and exit

    when I close openGL window the program still runs until I press ctrl+c. how can I close automatically the program without press ctrl+c?

  2. #2
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,294

    Re: close program and exit

    capture WM_CLOSE
    Code :
    case WM_CLOSE:
        PostQuitMessage(0);break;

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2009
    Posts
    22

    Re: close program and exit

    i'm working on linux...

  4. #4
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: close program and exit

    We need more information. How do create your opengl window? Using glut?

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2009
    Posts
    22

    Re: close program and exit

    static void create_frame_cube(GtkWidget *window){
    int returned = fork();
    if(returned != 0){
    glutInit(&argc_, argv_);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
    glutCreateWindow("Simple");
    glutDisplayFunc(RenderScene);
    glutKeyboardFunc(processNormalKeys);
    SetupRC();
    glutMainLoop();
    }
    }


    void RenderScene(void){
    glClear(GL_COLOR_BUFFER_BIT);
    glFlush();
    }
    void SetupRC(void){
    glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
    }

    void processNormalKeys(unsigned char key, int x, int y) {
    if (key == 27)
    exit(0);
    }

    I want exit with x window button pressing and free all resources. I have a GTK GUI with different command and I create a new process for the openGL program

  6. #6
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: close program and exit

    So you are forking! That's a piece of information.

    I guess you do not really know how forking work in unix based systems or the create_frame_cube function code is not complete.

    Parent and child processes have to be synchronized and I see only one code path for the child process in the create_frame_cube function...

  7. #7
    Junior Member Newbie
    Join Date
    Jul 2009
    Posts
    22

    Re: close program and exit

    child implement openGL function and parent manages GTK GUI

  8. #8
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: close program and exit

    Ok but as I said, it seems that in the provided code, there is only the opengl path.
    To make your program quit properly you have to kill the child process first then the parent.
    In the gtk process when you catch the close event call the kill( pid, SIGKILL ) function with the child pid to kill the opengl process.
    Also register a signal handler in the child process (opengl one) with the signal() function to handle the kill signal and release all allocated ressources.

  9. #9
    Junior Member Newbie
    Join Date
    Jul 2009
    Posts
    22

    Re: close program and exit

    can you give me an example?

Similar Threads

  1. Exit the Program when i close the last Window.
    By Bernardo Breder in forum OpenGL: Windows
    Replies: 3
    Last Post: 12-02-2008, 06:15 AM
  2. Event loop exit on close
    By Brolingstanz in forum OpenGL: Linux
    Replies: 2
    Last Post: 03-19-2008, 05:12 PM
  3. Close Program when click X on GLUT Window
    By shart75 in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 11-19-2007, 07:59 AM
  4. how to exit a program via a glut menu
    By Runz W Scissorz in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-21-2004, 01:14 PM
  5. Glut program exit
    By maxsteel in forum OpenGL: General
    Replies: 10
    Last Post: 08-02-2002, 09:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean