/*******************************************
添加静态库
*******************************************/
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glut32.lib")
#pragma comment(lib, "glaux.lib")
#pragma comment(lib, "vfw32.lib")
/*******************************************
包含头文件
*******************************************/
#include <windows.h>
#include <stdio.h>
#include <math.h>
#include <gl/GLAUX.H>
/*******************************************
定义全局变量
*******************************************/
#define MAX_PARTICLES 3000 // 定义最大粒子数
bool rainbow = true; // 是否为彩虹模式
bool sp; // 空格键是否被按下
bool rp; // 回车键是否被按下
float slowdown = 2.0f; // 减速粒子
float xspeed; // X方向的速度
float yspeed; // Y方向的速度
float zoom = -40.0f; // 沿Z轴缩放
GLuint loop; // 循环变量
GLuint col; // 当前颜色
GLuint delay; // 彩虹效果延迟
typedef struct // 创建粒子的数据结构
{
bool active; // 是否激活
float life; // 粒子生命
float fade; // 衰减速度
float r; // 红色值
float g; // 绿色值
float b; // 蓝色值
float x; // X 位置
float y; // Y 位置
float z; // Z 位置
float xi; // X 方向
float yi; // Y 方向
float zi; // Z 方向
float xg; // X 方向重力加速度
float yg; // Y 方向重力加速度
float zg; // Z 方向重力加速度
}particles; // end of 粒子数据结构
particles particle[MAX_PARTICLES]; // 保存3000个粒子的数组
static GLfloat colors[12][3] = // 彩虹颜色
{
{1.0f, 0.5f, 0.5f}, {1.0f, 0.75f, 0.5f}, {1.0f, 1.0f, 0.5f}, {0.75f, 1.0f, 0.5f},
{0.5f, 1.0f, 0.5f}, {0.5f, 1.0f, 0.75f}, {0.5f, 1.0f, 1.0f}, {0.5f, 0.75f, 1.0f},
{0.5f, 0.5f, 1.0f}, {0.75f, 0.5f, 1.0f}, {1.0f, 0.5f, 1.0f}, {1.0f, 0.5f, 0.75f}
};
GLfloat xrot; // X 旋转量
GLfloat yrot; // Y 旋转量
GLfloat zrot; // Z 旋转量
GLuint texture[1]; // 存储一个纹理
HDC hDC = NULL; // 窗口着色描述表句柄
HGLRC hRC = NULL; // OpenGL渲染描述表句柄
HWND hWnd = NULL; // 保存窗口句柄
HINSTANCE hInstance; // 保存程序的实例
bool keys[256]; // 保存键盘按键的数组
bool active = TRUE; // 窗口的活动标志,缺省为 TRUE
bool fullscreen = TRUE; // 全屏标志缺省,缺省设定为全屏模式
GLfloat rtri; // 用于三角形的角度
GLfloat rquad; // 用于四边形的角度
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // WndProc 的定义
AUX_RGBImageRec *LoadBMP(char *filename) // 载入位图图片
{
FILE *File = NULL; // 文件句柄
if(!filename) // 确保文件名已提供
{
return NULL; // 如果没有提供, 返回NULL
}
File = fopen(filename, "r"); // 尝试打开文件
if(File) // 文件是否存在?
{
fclose(File); // 关闭句柄
return auxDIBImageLoadA(filename); // 载入位图并返回指针
}
return NULL; // 如果载入失败,返回 NULL
}
int LoadGLTextures() // 载入位图并转换为纹理
{
int Status = FALSE; // 状态指示器
AUX_RGBImageRec *TextureImage[1]; // 创建纹理的存储空间
memset(TextureImage, 0, sizeof(void *)*1); // 将指针设为 NULL
// 载入位图,检查有无错误,如果位图没有找到则退出
if(TextureImage[0]=LoadBMP("Particle.bmp")) // 载入粒子纹理
{
Status = TRUE; // 将 Status 设为 TRUE
glGenTextures(1, &texture[0]); // 创建纹理
// 使用来自位图数据生成的典型纹理
glBindTexture(GL_TEXTURE_2D, texture[0]);
// 生成纹理
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // 线形滤波
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // 线形滤波
}
if(TextureImage[0]) // 纹理是否存在
{
if(TextureImage[0]->data) // 纹理图像是否存在
{
free(TextureImage[0]->data); // 释放纹理图像占用的内存
}
free(TextureImage[0]); // 释放图像结构
}
return Status; // 返回 Status 状态
}
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // 重置 OpenGL 窗口大小
{
if(height == 0) // 防止除零错误
{
height = 1; // 若 height == 0 将 height 设为 1
}
glViewport(0, 0, width, height); // 重置当前的视口
glMatrixMode(GL_PROJECTION); // 选择投影矩阵
glLoadIdentity(); // 重置投影矩阵
// 设置视口大小
gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW); // 选择模型观察矩阵
glLoadIdentity(); // 重置模型观察矩阵
}
int InitGL(GLvoid) // 初始化,对 OpenGL 进行所有设置
{
if(!LoadGLTextures()) // 调用纹理载入子例程
{
return false; // 如果未能载入,返回 false
}
glEnable(GL_TEXTURE_2D); // 启用纹理映射
glShadeModel(GL_SMOOTH); // 启用阴影平滑
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // 黑色背景
glClearDepth(1.0f); // 设置深度缓存
glDepthFunc(GL_LEQUAL); // 深度测试类型
glEnable(GL_DEPTH_TEST); // 开始深度测试
glShadeModel(GL_SMOOTH); // 选择阴影平滑
glDisable(GL_DEPTH_TEST); // 禁止深度测试
for(loop=0; loop<MAX_PARTICLES; loop++) // 初始化所有的粒子
{
particle[loop].active = true; // 使所有的粒子为激活状态
particle[loop].life = 1.0f; // 所有的粒子生命值为最大
particle[loop].fade = (float)(rand()%100)/1000.0f+0.003f; // 随机生成衰减速率
particle[loop].r = colors[loop*(12/MAX_PARTICLES)][0]; // 粒子的红色值
particle[loop].g = colors[loop*(12/MAX_PARTICLES)][1]; // 粒子的绿色值
particle[loop].b = colors[loop*(12/MAX_PARTICLES)][2]; // 粒子的蓝色值
particle[loop].xi = (float)((rand()%50)-25.0f)*10.0f; // 随机生成 X 轴方向速度
particle[loop].yi = (float)((rand()%50)-25.0f)*10.0f; // 随机生成 Y 轴方向速度
particle[loop].zi = (float)((rand()%50)-25.0f)*10.0f; // 随机生成 Z 轴方向速度
particle[loop].xg = (float)(rand()%50)/1000.0f; // 设置 X 轴方向加速度
particle[loop].yg = (float)(rand()%50)/1000.0f; // 设置 Y 轴方向加速度
particle[loop].zg = (float)(rand()%50)/1000.0f; // 设置 Z 轴方向加速度
}
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // 对透视进行修正
return TRUE; // 初始化成功
}
int DrawGLScene(GLvoid) // 进行所有绘制
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // 清楚屏幕和深度缓存
glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_CURRENT_BIT
| GL_LIGHTING_BIT | GL_TRANSFORM_BIT | GL_TEXTURE_BIT);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
glBlendFunc(GL_S
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Particle System.rar (37个子文件)
Particle System
Particle System.sdf 27.28MB
Particle System.sln 912B
Particle System.suo 20KB
ipch
particle system-87fa9a9a
particle system-95fe4f45.ipch 32.81MB
Debug
Particle System.exe 62KB
Particle.bmp 3KB
Particle System.ilk 629KB
Particle System.pdb 547KB
Particle System
Particle System.vcxproj.user 143B
Particle System.vcxproj.filters 946B
Particle.bmp 3KB
Particle.cpp 25KB
Debug
vc100.idb 371KB
Particle System.exe.embed.manifest 406B
CL.write.1.tlog 3KB
CL.read.1.tlog 17KB
mt.read.1.tlog 4KB
rc.write.1.tlog 3KB
Particle System.log 2KB
Particle System_manifest.rc 220B
rc.read.1.tlog 4KB
Particle System.lastbuildstate 60B
Particle System.exe.intermediate.manifest 381B
mt.command.1.tlog 444B
Particle.obj 60KB
cl.command.1.tlog 654B
link-cvtres.read.1.tlog 2B
link.write.1.tlog 3KB
link-cvtres.write.1.tlog 2B
link.command.1.tlog 2KB
rc.command.1.tlog 628B
link.read.1.tlog 7KB
mt.write.1.tlog 3KB
Particle System.exe.embed.manifest.res 68B
Particle System.Build.CppClean.log 3KB
vc100.pdb 108KB
Particle System.vcxproj 4KB
共 37 条
- 1
资源评论
- zhuyaer2015-01-04vs2010下运行了,很好用,不知道是不是我键盘设置的问题,按一些键没有反应。
- qinshengwu2014-01-28要是C#的就更好了,不过还是有很大参考的
a496817765
- 粉丝: 2
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功