本文介绍了多个Windows OpenGL/Glut的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何打开多个OpenGL/Glut窗口.我的意思是同时多个窗口没有子窗口和不更新同一窗口
I would like to know how to open multiple OpenGL/Glut windows.And I mean multiple windows at the same timenot subwindows andnot update the same window
推荐答案
与创建一个窗口的方式相同,只是您应多次创建该窗口:
The same way as you would create one window, except you should do it multiple times :
#include <cstdlib>
#include <GL/glut.h>
// Display callback ------------------------------------------------------------
float clr = 0.2;
void display()
{
// clear the draw buffer .
glClear(GL_COLOR_BUFFER_BIT); // Erase everything
// set the color to use in draw
clr += 0.1;
if ( clr>1.0)
{
clr=0;
}
// create a polygon ( define the vertexs)
glBegin(GL_POLYGON); {
glColor3f(clr, clr, clr);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f( 0.5, 0.5);
glVertex2f( 0.5, -0.5);
} glEnd();
glFlush();
}
// Main execution function
int main(int argc, char *argv[])
{
glutInit(&argc, argv); // Initialize GLUT
glutCreateWindow("win1"); // Create a window 1
glutDisplayFunc(display); // Register display callback
glutCreateWindow("win2"); // Create a window 2
glutDisplayFunc(display); // Register display callback
glutMainLoop(); // Enter main event loop
}
此示例显示如何设置相同的回调以在两个窗口中呈现.但是您可以为Windows使用不同的功能.
This example shows how to set the same callback to render in both windows. But you can use different functions for windows.
这篇关于多个Windows OpenGL/Glut的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!