资源简介
OpenGL编程示例,制作雪花飘落效果,有键盘和鼠标控制。
代码片段和文件信息
//////////////////////////////////////////////
// Double buffered resizeable 2D GL windowing environment using GLUT
//////////////////////////////////////////////
#include
#include
#include
#include
//
//globale variables
//
const int milliseconds_per_frame = 500;
float posX posY;
float posXA[100];
float posYA[100];
int sizeA[100];
float angleA[100];
int cnt=0;
int size=1;
int angle=0;
int filled = 1;
int animation=1;
int windowWidth=700;
int windowHeight=600;
//
// Forward declarations
//
void DrawScene();
void DrawSnow();
void DrawEdge();
void FillEdge();
//
// Initialisation functions
//
static void DrawInit()
{
// OpenGL one-time initialisation
glClearColor(0.65F 0.65F0.9F 1.0F);
cnt=0;
}
//
// Callbacks
//
void Timer(int id)
{
for(int i=0; i< cnt; i++)
{
angleA[i]+=(0.1+5/sizeA[i]);
posXA[i]+=0.25;
posYA[i]-=0.5;
if(posXA[i]>(windowWidth+50))
{
posXA[i]-=windowWidth;
}
if(posYA[i]<-50)
{
posYA[i]+=windowHeight;
}
}
glutPostRedisplay();
}
void DisplayFunc()
{
glShadeModel(GL_SMOOTH);
glClearColor(0.65F 0.65F0.9F 1.0F);
glClear(GL_COLOR_BUFFER_BIT);
if(animation)
glutTimerFunc(milliseconds_per_frameTimer1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
DrawScene();
glutSwapBuffers();
}
void PainSnow(int btn int state int x int y)
{
if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
{
size = rand()%5+1;
angle = rand()%30;
posX=x;
posY = windowHeight-y;
posXA[cnt]=posX;
posYA[cnt]=posY;
sizeA[cnt]=size;
angleA[cnt]=angle;
cnt++;
}
}
void KeyboardFunc(unsigned char key int x int y)
{
switch(key)
{
case ‘a‘ :
case ‘A‘ :
{
if(animation==0)
{
animation=1;
}else{
animation=0;
}
}
case ‘x‘ :
case (‘X‘):
{
cnt=0;
DrawInit();
break;
}
case ‘f‘:
case ‘F‘:
{
if(filled==1)
{
filled=0;
}
else
{
filled=1;
}
break;
}
case 27: // escape key pressed
{
exit(0);
break;
}
}
}
void ReshapeFunc( int x int y )
{
// Orthographic view fills the window
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D( 0.0 x 0.0 y );
glViewport( 0 0 x y );
windowWidth=x;
windowHeight=y;
}
void IdleFunc()
{
glutPostRedisplay();
}
void FillEdge()
{
glColor3f(0.70f 0.70f 1.0f);
glBegin(GL_POLYGON);
glVertex2f(0.0f 30.0f);
glVertex2f(0.0f 00.0f);
glVertex2f(260.0f 00.0f);
glVertex2f(250.0f 30.0f);
- 上一篇:基于模糊控制的速度跟踪控制问题
- 下一篇:c++分屏显示
相关资源
- 安卓c语言开发SDL2+opengles
- 交互式计算机图形学 第六版 OpenGL源代
- VC++基于OpenGL模拟的一个3维空间模型
- opengl绘制汽车.cpp
- opengl实现水流效果sph
- opengl源代码,全是精华!
- OpenGL迷宫山东大学图形学实验三
- opengl的立方体消隐算法
- vc++ opengl代码爆炸
- 我见过最漂亮的CS仿真程序openGL和C+
- 广东某工业大学的openGL课程设计
- 使用OpenGL实现多个小球在密闭空间内
- 利用openGL和C++实现光线跟踪绘图的完
- OpenGl C++太阳系小行星运行系统 可切换
- vc++和OpenGL实现三维地形实时动态显示
- C++实现利用OpenGL实现三维绘图
- 太阳、地球、月亮之间的运动图Open
- MFC 单文档 实现opengl 三维旋转 缩放
- OPENGL的烟花程序(代码)
- MFC+OpenGL三维建模与动画显示
- 基于opengl粒子系统实现喷泉的模拟
- 一个基于openGL的太阳系模型,太阳地
- vc6.0+opengl纯色五角星填充
- vc6.0+opengl动态绘制五角星
- NeHe_OpenGL教程完整版 里面有地址可以
- OpenGL简单——实现立方体贴上不同纹
- MFC实现dem的读取与现实
- VC++ OpenGL三维地形漫游
- OpenGL实现三维地形实时动态显示
- VC++中Opengl实现建筑物虚拟漫游
评论
共有 条评论