zoukankan      html  css  js  c++  java
  • 【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 }

    运行结果如下所示:

  • 相关阅读:
    hdu 4577 X-Boxes 大数
    hdu 4576 Robot 概率DP
    将IP地址转化为整数
    MyISAM压缩表
    yii2 模态框
    MySQL数据库设计
    foreach循环赋值问题
    实用的网站
    判断链接地址是否有效
    tp5获取配置文件信息
  • 原文地址:https://www.cnblogs.com/dragonir/p/5865961.html
Copyright © 2011-2022 走看看