C - Opengl - Question About glutMainLoop - Stack Overflow

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

opengl: question about glutMainLoop()

Asked 13 years, 10 months ago Modified 13 years, 10 months ago Viewed 2k times

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
0 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();
}

c opengl graphics glut

Share Improve this question Follow edited May 24, 2010 at 18:30 asked May 24, 2010 at 16:08
genpfault lego69
51.6k 11 88 142 817 1 13 20

2 Answers Sorted by: Highest score (default)

glutMainLoop() just runs a platform-specific event loop and calls any registered glut*Func() callbacks
as needed.
1
RenderScene() won't be called by GLUT until you call glutMainLoop() . So in reality glClearColor()
gets called first, not glClear() .
Share Improve this answer Follow answered May 24, 2010 at 18:26
genpfault
51.6k 11 88 142

glutDisplayFunc(RenderScene);

0 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 .

Share Improve this answer Follow answered May 25, 2010 at 15:37
Alan
4,925 2 24 17

You might also like