【openGL】画五角星

 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 }

运行结果如下所示:

 

转载于:https://www.cnblogs.com/dragonir/p/5865961.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值