当我将 OpenGL 与过剩一起使用时,为什么当我关闭 window 并重新打开它时它什么也没显示?

when I use OpenGL with glut, why it shows nothing when I close a window and reopen it?

我用freeglut创建windows,代码是这样的:

int window1, window2;
GLfloat cube[] = {
    //cube point
}

init2()
{
    //init shaders...
    //init vertex arrays with cube points...
}

void display2()
{
    glutSetWindow(window2);
    glViewport(0, 0, WIDTH, HEIGHT);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    glEnable(GL_DEPTH_TEST);

    mul.use();

    glm::mat4 view;
    view = camera.GetViewMatrix();
    glm::mat4 projection = glm::perspective(camera.Zoom, (GLfloat)WIDTH / (GLfloat)HEIGHT, 0.1f, 100.0f);

    mul.setUniform("view", view);
    mul.setUniform("projection", projection);
    glBindVertexArray(box_vao2);
    glDrawArrays(GL_QUADS, 0, 24);
    glBindVertexArray(0);
    glUseProgram(0);
    glutSwapBuffers();
}
openwin2()
{
    window2 = glutCreateWindow("win2");
    init2();
    glutDisplayFunc(display2);
    glutReshapeFunc(reshape2);
    glutIdleFunc(idle2);
}

void mouse(int button, int state, int x, int y)
{
    //do something and...
    openwin2();
}

int main(int argc, char **argv)
{
    //glutinit...

    window1 = glutCreateWindow("window1");
    init();
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMouseFunc(mouse);
    glutIdleFunc(idle);

    glutMainLoop();

    //...
}

所以,当我第一次点击打开window2时,它可以显示我用vao绘制的立方体,但是如果我关闭它并重新打开它,window没有任何作用,为什么?

是关于 vao 的吗?

我重用了之前 window 上下文创建的着色器,所以第二个 window 没有显示任何内容,因为着色器不属于它。