• 【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 }

    运行结果如下所示:

  • 相关阅读:
    Linux 基础
    Python 代码片段收藏
    Oracle数据库介绍
    Oracle11g数据库快速安装
    Oracle11g客户端安装配置
    Oracle环境变量
    Oracle数据类型
    Oracle的表
    Oracle事务
    Oracle的where子句
  • 原文地址:https://www.cnblogs.com/dragonir/p/5865961.html
Copyright © 2020-2023  润新知