2个回答

4

虽然我认为上面的回答是正确的,但它比必要的更复杂,当以后需要在窗口之间移动时(例如在绘图过程中),可能会很困难。以下是我们在课堂上所做的:

GLint WindowID1, WindowID2;                  // window ID numbers

glutInitWindowSize(250.0, 250.0);           // set a window size
glutInitWindowPosition(50,50);              // set a window position
WindowID1 = glutCreateWindow("Window One"); // Create window 1

glutInitWindowSize(500.0, 250.0);           // set a window size
glutInitWindowPosition(500,50);             // set a window position
WindowID2 = glutCreateWindow("Window Two"); // Create window 2

你会注意到我使用了相同的create window函数,但将其加载到GLint中。这是因为当我们以这种方式创建窗口时,该函数实际上返回一个唯一的GLint,由glut用于标识窗口。
我们必须获取和设置窗口以在它们之间移动并执行适当的绘图函数。你可以在这里找到调用方法

2

与创建一个窗口的方式相同,只是您需要多次执行此操作:

#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
}

这个例子展示了如何设置相同的回调函数来渲染两个窗口,但是你可以为不同的窗口使用不同的函数。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接