#include<GL/glut.h>
#include<math.h>
const int n=20;
const GLfloat PI=3.1415926535;
void init(void)
{
glClearColor(0.0,0.0,0.0,0.0);
// glMatrixMode(GL_PROJECTION);
// gluOrtho2D(0.0,4000.,0.0,400.0);
glColor3f(1.0,0.0,0.0);
}
void myDisplay()
{
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};
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINE_LOOP);
glVertex2fv(PointA);
glVertex2fv(PointC);
glVertex2fv(PointE);
glVertex2fv(PointB);
glVertex2fv(PointD);
glEnd();
glFlush();
}
void main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(100,100);
glutInitWindowSize(400,400);
glutCreateWindow("cicle");
init();
glutDisplayFunc(myDisplay);
glutMainLoop();
}
先考虑五个点的位置函数,进行计算和确定,然后依次连接五个点
Open GL 小练习 写五角星的代码
最新推荐文章于 2024-09-11 14:46:11 发布