1. 程式人生 > >OpenGL入門程序(二)

OpenGL入門程序(二)

lB void pla ++ polygon 入門 draw PV BE

學習

繪制一個圓:

const int n = 100;
const float Pi = 3.1415926536f;
const float R = 0.5f;
//繪制一個圓
void DrawCircle()
{
    //繪制一個多邊形 2Pi 是 180°
    GLfloat tempVal = 2 * Pi / n;
     
    //頂點需要放在 glBegin 和 glEnd 之間使用
    //並且由 glBegin 指明如何使用這些頂點
    glBegin(GL_POLYGON);
    for (size_t i = 0; i < n; ++i)
        glVertex2f(R 
* cos(tempVal * i), R * sin(tempVal * i)); glEnd(); }

在 Display() 掉用即可。

OpenGL入門程序(二)