本文介绍了opengl:关于glutMainLoop()的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释glutMainLoop的工作方式吗?第二个问题,为什么定义glClearColor(0.0f, 0.0f, 1.0f, 1.0f);glutDisplayFunc(RenderScene);原因之后,我们首先调用glClear(GL_COLOR_BUFFER_BIT);然后定义glClearColor(0.0f, 0.0f, 1.0f, 1.0f);

can somebody explain how does glutMainLoop work?and second question, why glClearColor(0.0f, 0.0f, 1.0f, 1.0f); definedafter glutDisplayFunc(RenderScene); cause firstly we call glClear(GL_COLOR_BUFFER_BIT);and only then define glClearColor(0.0f, 0.0f, 1.0f, 1.0f);

int main(int argc, char* argv[])
    {
        glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
        glutInitWindowSize(800, 00);
        glutInitWindowPosition(300,50);
    glutCreateWindow("GLRect");
    glutDisplayFunc(RenderScene);
        glutReshapeFunc(ChangeSize);
    glClearColor(0.0f, 0.0f, 1.0f, 1.0f);  <--
    glutMainLoop();

        return 0;
    }

void RenderScene(void)
    {
    // Clear the window with current clearing color
    glClear(GL_COLOR_BUFFER_BIT);

    // Set current drawing color to red
    //         R     G     B
    glColor3f(1.0f, 0.0f, 1.0f);

    // Draw a filled rectangle with current color
    glRectf(0.0f, 0.0f, 50.0f, -50.0f);

    // Flush drawing commands
    glFlush();
    }

推荐答案

glutMainLoop()仅运行特定于平台的事件循环,并根据需要调用任何已注册的glut*Func()回调.

glutMainLoop() just runs a platform-specific event loop and calls any registered glut*Func() callbacks as needed.

RenderScene().因此实际上glClearColor()首先被调用,而不是glClear().

RenderScene() won't be called by GLUT until you call glutMainLoop(). So in reality glClearColor() gets called first, not glClear().

这篇关于opengl:关于glutMainLoop()的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 22:43