-3

I use freeglut to create windows, and the code goes like this:

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();

    //...
}

So, when I click and open the window2 the first time, it can display the cube I draw with vao, but if I close it and reopen it, the window does nothing, why?

Is it something about the vao?

PandaChen
  • 11
  • 6
  • Something about *what* VAO? There's nothing in your code that involves a VAO. – Nicol Bolas Dec 05 '15 at 01:34
  • modified the question, I use a vao to store the cube points and use glDrawArrays to draw it. – PandaChen Dec 05 '15 at 02:01
  • sorry, I try to make it minimal but still I miss something. – PandaChen Dec 05 '15 at 02:47
  • if you have Intel gfx card it might be related to this [What is the proper OpenGL initialisation on Intel HD 3000?](http://stackoverflow.com/q/19099162/2521214) which is still open and unsolved question ... – Spektre Dec 05 '15 at 08:59

1 Answers1

0

I reuse the shader created by the previous window context, so the second window shows nothing because the shader doesn't belong to it.

PandaChen
  • 11
  • 6