Programming and Graphics

(Kiana) #1

274 Introduction to C++ Programming and Graphics


}

//--- Draw a circle:

void drawCircle()
{
glBegin(GLLINELOOP);
for (int i=0; i <= N; i++)
{
float angle = i*Dtheta;
glVertex2f(cos(angle)*radius,sin(angle)*radius);
}
glEnd();
}

In this method, animation is performed using theglutIdleFunccallback. The
code features the following implementations:



  • Double buffering is ensured by includingGLUTDOUBLEin the argument of
    glutInitDisplayMode.

  • It is mandatory to clear the depth buffer, otherwise the rendering will fail.

  • TheglutSwapBuffersfunction swaps the buffers.


A snapshot of the animation is shown in Figure 8.2.1(a).


(a)(b)

Figure 8.2.1 Snapshot of (a) a rotating circle, and (b)abouncingdisk.
Free download pdf