如何使用Mac关闭GLUT窗口

时间:2019-08-01 11:41:07

标签: c++ macos opengl glut

我正在尝试在MacOS Mojave 10.14.5终端中使用g ++-9 -framework GLUT -framework OpenGL编译的程序中关闭OpenGL的窗口 我尝试使用glutDestroyWindow(),但得到警告:   GLUT警告:在虚假窗口0上尝试了glutDestroyWindow

我有一个正在旋转的圆锥体,并通过一系列数据实现其旋转。我希望动画在数组完成元素后立即停止。

  void idleCone(void)
{
    for(int j = 1; j<10000 ; j++){
        double i = dati[j+1][0];

        int win = glutGetWindow();
        if(i == 0.) {     glutDestroyWindow(win);
        }
        xRotated = 180/M_PI*(dati[j][0]);
        yRotated = 180/M_PI*(dati[j][1]);
        zRotated = 180/M_PI*(dati[j][2]);

        displayCone();
        xRotated += 0.;
        yRotated += 0.;
        zRotated += 0.;
        displayCone();

    }}

dati在哪里:

   std::vector<std::array<GLfloat, 3>> &dati

主要我有

glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
                xRotated = yRotated = zRotated = 0.0;
                xRotated=0.0;
                yRotated=0.0;
                glClearColor(0.0,0.0,0.0,0.0);


                glutDisplayFunc(displayCone);
                glutReshapeFunc(reshapeCone);
                glutIdleFunc(idleCone);

                glutMainLoop();

这是displayCone函数

void displayCone(void){

    // clear the drawing buffer.
    glClear(GL_COLOR_BUFFER_BIT);  //

    // set matrix mode
    glMatrixMode(GL_MODELVIEW);
    // clear model view matrix
    glLoadIdentity();
    // multiply view matrix to current matrix
    gluLookAt(3.0, 3.0, 3.0-4.5, 0.0, 0.0,-4.5,0,1,0);

    // ******
    glPushMatrix();


    glTranslatef(0.0, 0.0, -4.5);

    glBegin(GL_LINES);

    glColor3f (1.0, 1.0, 0.0);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(2.0, 0.0, 0.0);

    glColor3f (1.0, 1.0, 0.0);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(0.0, 2.0, 0.0);

    glColor3f (1.0, 1.0, 0.0);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(0.0, 0.0, 2.0);
    glEnd();

    glPopMatrix();

    // clear the drawing buffer.
    // glClear(GL_COLOR_BUFFER_BIT);  // <---- delete

    // traslate the draw by z = -4.0
    // Note this when you decrease z like -8.0 the drawing will looks far , or smaller.
    glTranslatef(0.0,0.0,-4.5);
    // Red color used to draw.
    glColor3f(0.8, 0.2, 0.1);
    // changing in transformation matrix.
    // rotation about X axis
    glRotatef(xRotated,1.0,0.0,0.0);
    // rotation about Y axis
    glRotatef(yRotated,0.0,1.0,0.0);
    // rotation about Z axis
    glRotatef(zRotated,0.0,0.0,1.0);

    // scaling transfomation
    glScalef(1.0,1.0,1.0);
    // built-in (glut library) function , draw you a Cone.

    // move the peak of the cone to the origin
    glTranslatef(0.0, 0.0, -height);

    glutSolidCone(base,height,slices,stacks);
    // Flush buffers to screen
    // gluLookAt(3,3,3,0,0,-4.5,0,1,0); <----------------------- delete

    glFlush();
    // sawp buffers called because we are using double buffering
    // glutSwapBuffers();

}

我也尝试使用

exit(0) 

但是我希望程序继续播放动画。 我知道我应该使用诸如glutLeaveMainLoop()之类的方法,但是由于Mac提示

,我仍然无法执行此操作
Undefined symbols for architecture x86_64:
  "_glutLeaveMainLoop", referenced from:
      idleCone()    in ccnOmxBT.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

即使我包括freeglut.h。有什么办法可以从包括freeglut.h的终端进行编译或成功关闭窗口?

0 个答案:

没有答案