opengl: question about glutMainLoop()

只谈情不闲聊 提交于 2019-12-25 01:49:23

问题


can somebody explain how does glutMainLoop work? and second question, why glClearColor(0.0f, 0.0f, 1.0f, 1.0f); defined after 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();
    }

回答1:


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

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




回答2:


glutDisplayFunc(RenderScene);

This only sets the callback function, it doesn't actually call it until it enters the main app loop in the call to glutMainLoop. So glClearColor comes before glClear.



来源:https://stackoverflow.com/questions/2898357/opengl-question-about-glutmainloop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!