Glut timer function burns my CPU

Hello,
I make a short 2D graphical application that is redrawn every 50 milliseconds. I use glut so i connected my redraw function to the glut timer using glutTimerFunc.
The problem I have is that it burns my CPU! As i make a real-time application which processes input data, my graphic must save the CPU at most.
Here is the code I connect to the glut timer :

void timerFunction(int arg)
{
rectangle.redraw(); //just calls a display list
glutSwapBuffers();
glutTimerFunc(50, timerFunction, 0);
}

So I would like that my graphic consumes CPU only when it is time to refresh.

Any ideas?

Thanks in advance.

You should never directly call a draw routine. This could potentially lock up your display if your CPU/GPU is not able to keep up with the rate you invoke the draw routine.

Instead, register a redraw routine using glutDisplayFunc(). Then, mark the display to be redrawn using glutPostRedisplay().

glutDisplayFunc(DrawCb);
...
void timerFunction(int arg)
{
   glutPostRedisplay();
   glutTimerFunc(50, timerFunction, 0);
}
void DrawCb(void)
{
   rectangle.redraw(); //just calls a display list
   glutSwapBuffers();
}

Ok, thank you!