OpenGL 五角星用 vs 做的五角星代码 void myDisplay(void)
{
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.5f, 1.0f);
glBegin(GL_POLYGON);
for (i = 0; i < n; i)
glVertex2f(R * cos(2 * Pi / n * i), R * sin(2 * Pi / n * i));
glEnd();
//五角星
glColor3f(0.0f, 1.0f, 1.0f);
GLfloat a = 1 / (2 - 2 * cos(72 * Pi / 180));
GLfloat bx = a * cos(18 * Pi / 180);
GLfloat by = a * sin(18 * Pi / 180);
GLfloat cy = -a * cos(18 * Pi / 180);
GLfloat
PointA[2] = { 0, a }, PointB[2] = { bx, by },
PointC[2] = { 0.5, cy }, PointD[2] = { -0.5, cy },
PointE[2] = { -bx, by };
glBegin(GL_LINE_LOOP);
glVertex2fv(PointA); glVertex2fv(PointC);
glVertex2fv(PointE); glVertex2fv(PointB);
glVertex2fv(PointD);
glEnd();
glFlush();//函数启动OpenGL绘图命令的执行,并将图形光栅化后输出在设备上。</span>
}
评论