OpenGL entry program (2)

Learn

Draw a circle:

const  int n = 100 ;
 const  float Pi = 3.1415926536f ;
 const  float R = 0.5f ;
 // Draw a circle 
void DrawCircle()
{
    // Draw a polygon 2Pi is 180° 
    GLfloat tempVal = 2 * Pi / n;
     
    // Vertices need to be used between glBegin and glEnd
     // and glBegin specifies how to use these vertices 
    glBegin(GL_POLYGON);
     for (size_t i = 0 ; i < n; ++ i)
        glVertex2f(R * cos(tempVal * i), R * sin(tempVal * i));
    glEnd();
}

 

It can be used in Display().

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325303032&siteId=291194637