博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
openGL 六边形
阅读量:4628 次
发布时间:2019-06-09

本文共 2193 字,大约阅读时间需要 7 分钟。

#include "stdafx.h"#include
#include
#include
const double TWO_PI = 6.2831853;/*Initial display-window size*/GLsizei winWidth = 400, winHeight = 400;GLuint regHex;class screenPt{private: GLint x, y;public: /*Default Constructor:initalizes coordinate position to(0,0).*/ screenPt() { x = y = 0; } void setGoords(GLint xGoord, GLint yGoord) { x = xGoord; y = yGoord; } GLint getx()const { return x; } GLint gety()const { return y; }};static void init(void){ screenPt hexVertex, circCtr; GLdouble theta; GLint k; /*Set circle center coordinates.*/ circCtr.setGoords(winWidth / 2, winHeight / 2); glClearColor(1.0, 1.0, 1.0, 0.0);//Display-window color=white. /*Set up a display list for a red regular hexagon. *Vertice for the hexagon are six equally spaced *points around the circumference of a circle. */ regHex = glGenLists(1);//Get an identifier for the display list. glNewList(regHex, GL_COMPILE); glColor3f(1.0, 0.0, 0.0);//Set fill color for hexagon to red. glBegin(GL_POLYGON); for (k = 0; k < 6; k++) { theta = TWO_PI*k / 6.0; hexVertex.setGoords(circCtr.getx() + 150 * cos(theta), circCtr.gety() + 150 * sin(theta)); glVertex2i(hexVertex.getx(), hexVertex.gety()); } glEnd(); glEndList();}void regHexagon(void){ glClear(GL_COLOR_BUFFER_BIT); glCallList(regHex); glFlush();}void winReshapeFcn(GLint newWidth, GLint newHeight){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, (GLdouble)newWidth, 0.0, (GLdouble)newHeight); glClear(GL_COLOR_BUFFER_BIT);}void main(int argc, char** argv){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowPosition(100, 100); glutInitWindowSize(winWidth, winHeight); glutCreateWindow("Reshape-Function&Display-ListExample"); init(); glutDisplayFunc(regHexagon); glutReshapeFunc(winReshapeFcn); glutMainLoop();}

 

 

转载于:https://www.cnblogs.com/pqhuang/p/11268936.html

你可能感兴趣的文章
LeetCode之461. Hamming Distance
查看>>
HSSFWorkbook 与 XSSFWorkbook
查看>>
希尔排序——算法系列
查看>>
javascript ES6 新特性之 扩展运算符 三个点 ...
查看>>
Jetson tk1 安装 CUDA,ROS,OpenCV和kinect2以及刷机以及ssh远程控制
查看>>
linux 下byte,char,unsigned char的区别
查看>>
Linux内核初期内存管理---memblock(转)
查看>>
黑客第一课
查看>>
Centos7 安装 telnet 服务
查看>>
Windows Azure Virtual Network (6) 设置Azure Virtual Machine固定公网IP (Virtual IP Address, VIP) (1)...
查看>>
3.1、final、finally、 finalize
查看>>
国家气象局提供的天气预报接口
查看>>
MongoDB 删除数据库
查看>>
前端基础之JQuery
查看>>
AppStore SDK
查看>>
springboot 学习笔记(三)
查看>>
Nginx 主要应用场景
查看>>
记录一次爬取某昵称网站的爬虫
查看>>
lattice diamond 3.7安装破解
查看>>
FPGA研发之道(25)-管脚
查看>>