GLGL_DOUBLE和两个窗口的OpenGL问题

时间:2013-09-25 16:58:07

标签: c++ opengl buffer glut

我正在使用Sumanta Guha的代码示例,我正在尝试创建两个窗口。使用以下代码:

int main(int argc, char **argv) 
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);

// First top-level window definition.
glutInitWindowSize(250, 500); 
glutInitWindowPosition(100, 100);

// Create the first window and return id.
id1 = glutCreateWindow("windows.cpp - window 1"); 

// Initialization, display, and other routines of the first window. 
setup1();
glutDisplayFunc(drawScene1); 
glutReshapeFunc(resize1);
glutKeyboardFunc(keyInput); // Routine is shared by both windows.

// Second top-level window definition.
glutInitWindowSize(250, 500); 
glutInitWindowPosition(400, 100);

// Create the second window and return id.
id2 = glutCreateWindow("windows.cpp - window 2"); 

// Initialization, display, and other routines of the second window. 
setup2(); 
glutDisplayFunc(drawScene2); 
glutReshapeFunc(resize2);
glutKeyboardFunc(keyInput); // Routine is shared by both windows.

glutMainLoop();

return 0;   
}

我正在使用Windows 7,通常它应该显示两个窗口。但正如您所看到的,只有一个窗口正确显示而另一个窗口似乎不能正常工作。除了GLUT_DOUBLE和缓冲交换之外,我还需要采取其他步骤吗?

enter image description here

1 个答案:

答案 0 :(得分:1)

  

除了GLUT_DOUBLE和缓冲交换之外,我还需要采取其他步骤吗?

由于您要创建多个窗口,因此必须在回调中调用glutSetWindow()

freeglut有一个扩展(不起作用)来创建一个共享的opengl上下文,但原始的过剩不支持它。