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

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

#include "stdafx.h"#include
#include
#include
#include
const double TWO_PI = 6.2831853;/*Initial display-window size*/GLsizei winWidth = 800, winHeight = 600;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; }};void drawcloud (GLint x, GLint y, GLint z){ GLdouble theta; GLint k; glBegin(GL_POLYGON); for (k = 0; k < 360; k++) { theta = TWO_PI*k / 360.0; glVertex2f(x * cos(theta) + y,x * sin(theta) + z); } glEnd();}//画云二的过程static void init(void){ screenPt hexVertex, circCtr; GLdouble theta; GLint k,j; srand((int)time(0)); circCtr.setGoords(0, winHeight ); glClearColor(1.0, 1.0, 1.0, 0.0); regHex = glGenLists(1); glNewList(regHex, GL_COMPILE); /*添加*/ glShadeModel(GL_SMOOTH); glBegin(GL_QUADS); glColor3f(0.6,0.8,0.9); glVertex2f(0.0, 0.0); glVertex2f(winWidth, 0.0); glColor3f(0.0,0.2,0.8); glVertex2f(winWidth, winHeight); glColor3f(1.0, 1.0, 1.0); glVertex2f(0.0, winHeight);//背景 glEnd(); glEnable(GL_POINT_SMOOTH); glPointSize(15.0); glBegin(GL_POINTS); for (j = 0; j <= 8;j++) { glColor3f(0.60 + j*0.05, 0.60 + j*0.05, 0.60 + j * 0.05); for (k = 0; k < (25-j); k++) { glVertex2f(490 + j * 5 + k * 10, 100 + j * 5 + rand() % 8); } }//cloud1 glEnd(); /*draw cloud2*/ glColor3f(0.9, 0.9, 0.9); for (GLint i = 3; i <=8; i++) { drawcloud(100 / i, 400 + i * 15, 500 + rand() % 10); }//云的腰 for (GLint i = 9; i <13; i++) { drawcloud(500/ (i*i), 480+i*5, 500 + rand() % 5); }//云的尾巴 glColor3f(0.91, 0.91, 0.91); drawcloud(30, 400, 500); drawcloud(30, 420, 530);//云的头 /*draw cloud 3*/ glColor3f(1.0, 1.0, 1.0); drawcloud(30, 300, 400); drawcloud(30, 320, 430); drawcloud(30, 340, 410); for (int i = 1; i < 20; i++) { glColor3f(1.0, 1.0,1.0); glPointSize(20.0-i); glBegin(GL_POINTS); glVertex2f(290-i, 380-i+ rand() % 5); glEnd();//云的角 } glColor3f(1.0, 1.0,1.0); for (GLint i = 3; i <= 8; i++) { drawcloud(100 / i, 300 + i * 15, 400 + rand() % 10); }//云的腰 for (int i = 1; i < 20; i++) { glColor3f(1.0, 1.0, 1.0); glPointSize(20.0 - i); glBegin(GL_POINTS); glVertex2f(430 +i, 410 -rand() % 5); glEnd();//云的尾巴2 } /*draw cloud 4*/ glColor3f(0.9, 0.9, 0.9); for (GLint i = 3; i <=8; i++) { drawcloud(100 / i, 200 + i * 15, 200 + rand() % 10); }//云的腰 for (GLint i = 9; i <13; i++) { drawcloud(500/ (i*i), 280+i*5, 200 + rand() % 5); }//云的尾巴 glColor3f(0.91, 0.91, 0.91); drawcloud(30, 200, 200); drawcloud(30, 220, 230);//云的头 glColor3f(1.0, 1.0, 1.0);//Set fill color for sun white glBegin(GL_POLYGON); for (k = 0; k < 360; k++) { theta = TWO_PI*k / 360.0; hexVertex.setGoords(circCtr.getx() + 80 * cos(theta), circCtr.gety() + 80* 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(200, 100); glutInitWindowSize(winWidth, winHeight); glutCreateWindow("blue_sky_and_white_cloud"); init(); glutDisplayFunc(regHexagon); glutReshapeFunc(winReshapeFcn); glutMainLoop();}

 

 

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

你可能感兴趣的文章
3.1、final、finally、 finalize
查看>>
国家气象局提供的天气预报接口
查看>>
MongoDB 删除数据库
查看>>
前端基础之JQuery
查看>>
AppStore SDK
查看>>
springboot 学习笔记(三)
查看>>
Nginx 主要应用场景
查看>>
记录一次爬取某昵称网站的爬虫
查看>>
lattice diamond 3.7安装破解
查看>>
FPGA研发之道(25)-管脚
查看>>
BFS之三(单向bfs和康托压缩)
查看>>
Web App、Hybrid App与Native App的设计差异
查看>>
ASP.NET将原始图片按照指定尺寸等比例缩放显示图片
查看>>
测试用例设计方法基础理论知识
查看>>
基于visual Studio2013解决面试题之0804复杂链表
查看>>
find_in_set
查看>>
【转帖】SQLServer登录连接失败(error:40-无法打开到SQLServer的连接)的解决方案...
查看>>
ibatis的there is no statement named xxx in this SqlMap
查看>>
系统启动时,spring配置文件解析失败,报”cvc-elt.1: 找不到元素 'beans' 的声明“异常...
查看>>
《Python学习手册》读书笔记
查看>>