代码: //#define _USE_MATH_DEFINES #include<GL/glut.h> #include<math.h> void display(void) { GLfloat ii,t=3,n=2*t+1,m=100; glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POLYGON); glColor3f(0,.3,0); for(ii=0;ii<=m;++ii) glVertex2f(cos(M_PI*2*ii/m),sin(M_PI*2*ii/m)); glEnd(); glLineWidth(5); glBegin(GL_LINE_LOOP); glColor3f(1,0.5,0); for(ii=1;ii<=t*n;ii=ii+t) glVertex2f(cos(M_PI*2.0*ii/n),sin(M_PI*2.0*ii/n)); glEnd(); glFlush(); } void init(void) { glClearColor (0,0,0.1,1); glColor3f(0,0,.8); } int main(int argc, char** argv) { glutInit(&argc, argv); // glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (500, 500); glutInitWindowPosition (10, 10); glutCreateWindow("七角星"); glutDisplayFunc(display); init(); glutMainLoop(); } 如果用VC,需要加上 #define _USE_MATH_DEFINES