【openGL】画五角星

时间:2023-03-10 04:16:34
【openGL】画五角星
 #include "stdafx.h"
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h> const GLfloat PI = 3.14159265357f;
void myDisplay(void) {
GLfloat a = / ( - * cos( * PI / ));
GLfloat bx = a*cos( * PI / );
GLfloat by = a*sin( * PI / );
GLfloat cy = -a*cos( * PI / );
GLfloat pointB[] = { bx, by },
pointC[] = { 0.5, cy },
pointD[] = { -0.5, cy },
pointE[] = { -bx, by },
pointA[] = { ,a };
glClear(GL_COLOR_BUFFER_BIT); //按照A->C->E->B->D->A的顺序一笔画出五角星
glBegin(GL_LINE_LOOP);
glVertex2fv(pointA);
glVertex2fv(pointC);
glVertex2fv(pointE);
glVertex2fv(pointB);
glVertex2fv(pointD);
glVertex2fv(pointA);
glEnd();
glFlush();
} int main(int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(, );
glutInitWindowSize(, );
glutCreateWindow("OpenGL画圆程序");
glutDisplayFunc(&myDisplay);
glutMainLoop();
return ;
}

运行结果如下所示:

【openGL】画五角星