The X Toolkit's work procedure facility makes it easy to integrate continuous OpenGL animation with Motif user interface operation. Work procedures are application supplied routines that execute while the application is idle waiting for events. Work procedures should be used to do small amounts of work; if too much time is spent in a work procedure, X events will not be processed and program interactivity will suffer.
Rendering a single frame of OpenGL animation is a good use for work procedures. XtAppAddWorkProc and XtRemoveWorkProc are used to add and remove work procedures. XtAppAddWorkProc is passed a function pointer for the routine to be called as a work procedure. The function to be called returns a Boolean. If the function returns True, the work procedure should be removed automatically; returning False indicates the work procedure should remain active. XtAppAddWorkProc returns an ID of type WorkProcId which can later be given to XtRemoveWorkProc to remove the work procedure.
The paperplane example uses a work procedure to manage the update of its 3D scene. In response to changing the state of the ``Motion'' toggle button on the ``Planes'' pulldown menu, the toggle callback routine will add and remove the animate work procedure.
The animate routine calls tick which advances the position of each active plane; animate then calls draw to redraw the scene with the new plane locations. Finally, animate returns False to leave the work procedure installed so that the animation will continue.
Because paperplane uses a work procedure, animation of the scene does not interfere with window resizing and user input. The X Toolkit manages both the animation and events from the X server.