画五角星

来源:互联网 发布:软件打开账套 编辑:程序博客网 时间:2024/04/28 11:47
#include <gl/glut.h>
#pragma comment(lib,"glut.lib")
#include<math.h>
#define PI 3.14
//进行绘制
void DrawGLScene(GLvoid)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glClearColor(0,0,0,0);


    double point[5][2];
    for(int i=0; i<5; i++)
    {
        point[i][0] = 0.9*cos(2*PI/5*i);
        point[i][1] = 0.9*sin(2*PI/5*i);
    }

    glBegin(GL_LINES);
    for(int i=0; i<5; i++)
    {
        glVertex2f(point[i][0],point[i][1]);
        glVertex2f(point[(i+2)%5][0],point[(i+2)%5][1]);
        
        glVertex2f(point[i][0],point[i][1]);
        glVertex2f(point[(i+3)%5][0],point[(i+3)%5][1]);
    }
    glEnd();
    glFlush();
}
void main(int argc, char *argv[])
{
    glutInit(&argc,argv);
    glutInitDisplayMode( GLUT_RGBA );
    glutInitWindowPosition(100,100);
    glutInitWindowSize(800,800);
    glMatrixMode(GL_PROJECTION);

    glutCreateWindow("Test");

    glutPositionWindow(100,100);

    glutDisplayFunc(DrawGLScene);
    glutMainLoop();
}
原创粉丝点击