我使用freeglut创建窗口,代码如下:
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绘制的立方体,但如果我关闭它并重新打开它,窗口什么都不做,为什么?
这是关于vao的吗?
答案 0 :(得分:0)
我重复使用前一个窗口上下文创建的着色器,因此第二个窗口不显示任何内容,因为着色器不属于它。