码迷,mamicode.com
首页 > 其他好文 > 详细

【openGL】画五角星

时间:2016-09-12 20:25:49      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:

 1 #include "stdafx.h"
 2 #include <GL/glut.h>
 3 #include <stdlib.h>
 4 #include <math.h>
 5 #include <stdio.h>
 6 
 7 const GLfloat PI = 3.14159265357f;
 8 void myDisplay(void) {
 9     GLfloat a = 1 / (2 - 2 * cos(72 * PI / 180));
10     GLfloat bx = a*cos(18 * PI / 180);
11     GLfloat by = a*sin(18 * PI / 180);
12     GLfloat cy = -a*cos(18 * PI / 180);
13     GLfloat pointB[2] = { bx, by },
14         pointC[2] = { 0.5, cy },
15         pointD[2] = { -0.5, cy },
16         pointE[2] = { -bx, by },
17         pointA[2] = { 0,a };
18     glClear(GL_COLOR_BUFFER_BIT);
19 
20     //按照A->C->E->B->D->A的顺序一笔画出五角星
21     glBegin(GL_LINE_LOOP);
22     glVertex2fv(pointA);
23     glVertex2fv(pointC);
24     glVertex2fv(pointE);
25     glVertex2fv(pointB);
26     glVertex2fv(pointD);
27     glVertex2fv(pointA);
28     glEnd();
29     glFlush();
30 }
31 
32 int main(int argc, char *argv[]) {
33     glutInit(&argc, argv);
34     glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
35     glutInitWindowPosition(100, 100);
36     glutInitWindowSize(500, 500);
37     glutCreateWindow("OpenGL画圆程序");
38     glutDisplayFunc(&myDisplay);
39     glutMainLoop();
40     return 0;
41 }

运行结果如下所示:

技术分享

 

【openGL】画五角星

标签:

原文地址:http://www.cnblogs.com/dragonir/p/5865961.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!