使用了opengl+粒子系统模拟的一个简单的降雪过程,其中雪片随机使用了7种不同的纹理,使雪花体现出差异性,并且使用了显示列表,对降雪过程进行优化,运行后左上角显示了帧速率和当前帧。
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-02-17 08:34 snow1 - 副本
目录 0 2014-02-17 08:34 snow1 - 副本1
文件 4413 2014-02-16 15:51 snow1 - 副本11.cpp
文件 4115 2013-12-23 11:13 snow1 - 副本11.vcxproj
文件 1167 2013-12-23 11:13 snow1 - 副本11.vcxproj.filters
文件 143 2013-12-23 11:04 snow1 - 副本11.vcxproj.user
目录 0 2014-02-17 08:34 snow1 - 副本1Debug
文件 406 2013-12-23 11:05 snow1 - 副本1Debug1.exe.embed.manifest
文件 472 2014-01-13 10:59 snow1 - 副本1Debug1.exe.embed.manifest.res
文件 381 2014-02-16 15:51 snow1 - 副本1Debug1.exe.intermediate.manifest
文件 107 2014-02-16 15:51 snow1 - 副本1Debug1.lastbuildstate
文件 3046 2014-02-16 15:51 snow1 - 副本1Debug1.log
文件 40345 2014-02-16 15:51 snow1 - 副本1Debug1.obj
文件 192 2013-12-23 11:05 snow1 - 副本1Debug1_manifest.rc
文件 87954 2014-02-16 15:51 snow1 - 副本1DebugCL.read.1.tlog
文件 4490 2014-02-16 15:51 snow1 - 副本1DebugCL.write.1.tlog
文件 40473 2014-01-13 10:59 snow1 - 副本1DebugTexture.obj
文件 4410 2014-02-16 15:51 snow1 - 副本1Debugcl.command.1.tlog
文件 2 2014-02-16 15:51 snow1 - 副本1Debuglink-cvtres.read.1.tlog
文件 2 2014-02-16 15:51 snow1 - 副本1Debuglink-cvtres.write.1.tlog
文件 2 2014-02-16 15:51 snow1 - 副本1Debuglink.12336-cvtres.read.1.tlog
文件 2 2014-02-16 15:51 snow1 - 副本1Debuglink.12336-cvtres.write.1.tlog
文件 2 2014-02-16 15:51 snow1 - 副本1Debuglink.12336.read.1.tlog
文件 2 2014-02-16 15:51 snow1 - 副本1Debuglink.12336.write.1.tlog
文件 2 2014-02-16 15:51 snow1 - 副本1Debuglink.12576-cvtres.read.1.tlog
文件 2 2014-02-16 15:51 snow1 - 副本1Debuglink.12576-cvtres.write.1.tlog
文件 2 2014-02-16 15:51 snow1 - 副本1Debuglink.12576.read.1.tlog
文件 2 2014-02-16 15:51 snow1 - 副本1Debuglink.12576.write.1.tlog
文件 2 2014-02-16 15:51 snow1 - 副本1Debuglink.3704-cvtres.read.1.tlog
文件 2 2014-02-16 15:51 snow1 - 副本1Debuglink.3704-cvtres.write.1.tlog
文件 2 2014-02-16 15:51 snow1 - 副本1Debuglink.3704.read.1.tlog
............此处省略74个文件信息
#include
#include
#include
#include
#include
#include “Texture.h“
#define PARTICLE_NUMBER 2000
GLuint texture[8];
int frame=0time=0base=0totalframe=0;
char fps[30]={‘ ‘};
char f[30]={‘ ‘};
float FPS=0.0f;
typedef struct
{
GLfloat xyz;
GLfloat r;
GLfloat life;
GLfloat vyvx;
GLfloat ayax;
}particle;
particle particles[PARTICLE_NUMBER];
void initparticles()
{
for (int i=0;i {
particles[i].life=rand()%200;
particles[i].r=rand()%3+1;
particles[i].x=rand()%250;
particles[i].y=rand()%30+150;
particles[i].z=rand()%200-100;
particles[i].vy=float(rand()%10-4)/40;
particles[i].vx=float(rand()%10-4)/80;
particles[i].ay=-4.9/40000;
particles[i].ax=-1.0/10000;
}
}
void init(void)
{
glClearColor(0.00.00.00.0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glColor4f(1.01.01.00.5f);
glBlendFunc(GL_SRC_ALPHAGL_ONE);
initparticles();
BuildTexture(“snow1.jpg“texture[0]);
BuildTexture(“num1.jpg“texture[1]);
BuildTexture(“num3.jpg“texture[2]);
BuildTexture(“num2.jpg“texture[3]);
BuildTexture(“num4.jpg“texture[4]);
BuildTexture(“num5.jpg“texture[5]);
BuildTexture(“num6.jpg“texture[6]);
BuildTexture(“num7.jpg“texture[7]);
glNewList(8GL_COMPILE);
glBegin(GL_QUADS);
glTexCoord2f(00);glVertex3f(-1-10.0);
glTexCoord2f(10);glVertex3f(1-10.0);
glTexCoord2f(11);glVertex3f(110.0);
glTexCoord2f(01);glVertex3f(-110.0);
glEnd();
glEndList();
for (int i=1;i<8;i++)
{
glNewList(iGL_COMPILE);
glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBindTexture(GL_TEXTURE_2Dtexture[i]);
glCallList(8);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glEndList();
}
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
// glEnable(GL_TEXTURE_2D);
// glBindTexture(GL_TEXTURE_2Dtexture[0]);
// glBegin(GL_QUADS);
// glTexCoord2f(00);glVertex3f(-240.0-220.0-150.0);
// glTexCoord2f(10);glVertex3f(240.0-220.0-150.0);
// glTexCoord2f(11);glVertex3f(240.0220.0-150.0);
// glTexCoord2f(01);glVertex3f(-240.0220.0-150.0);
// glEnd();
// glDisable(GL_TEXTURE_2D);
for (int i=0;i {
if(particles[i].life>0)
{
int j=rand()%7+1;
glPushMatrix();
glTranslatef(particles[i].xparticles[i].yparticles[i].z);
glScalef(particles[i].rparticles[i].r1.0);
glCallList(j);
glPopMatrix();
particles[i].life-=float(rand()%100)/1000.0f+0.0003f;
particles[i].vy+=particles[i].ay;
particles[i].vx+=particles[i].ax;
particles[i].y+=particles[i].vy;
particles[i].x+=particles[i].vx;
}
if(particles[i].life<=0)
{
particles[i].life=rand()%200;
particles[i].r=rand()%3+1;
particles[i].x=rand()%250;
particles[i].y=rand()%30+150;
particles[i].z=rand()%200-1
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-02-17 08:34 snow1 - 副本
目录 0 2014-02-17 08:34 snow1 - 副本1
文件 4413 2014-02-16 15:51 snow1 - 副本11.cpp
文件 4115 2013-12-23 11:13 snow1 - 副本11.vcxproj
文件 1167 2013-12-23 11:13 snow1 - 副本11.vcxproj.filters
文件 143 2013-12-23 11:04 snow1 - 副本11.vcxproj.user
目录 0 2014-02-17 08:34 snow1 - 副本1Debug
文件 406 2013-12-23 11:05 snow1 - 副本1Debug1.exe.em
文件 472 2014-01-13 10:59 snow1 - 副本1Debug1.exe.em
文件 381 2014-02-16 15:51 snow1 - 副本1Debug1.exe.intermediate.manifest
文件 107 2014-02-16 15:51 snow1 - 副本1Debug1.lastbuildstate
文件 3046 2014-02-16 15:51 snow1 - 副本1Debug1.log
文件 40345 2014-02-16 15:51 snow1 - 副本1Debug1.obj
文件 192 2013-12-23 11:05 snow1 - 副本1Debug1_manifest.rc
文件 87954 2014-02-16 15:51 snow1 - 副本1DebugCL.read.1.tlog
文件 4490 2014-02-16 15:51 snow1 - 副本1DebugCL.write.1.tlog
文件 40473 2014-01-13 10:59 snow1 - 副本1DebugTexture.obj
文件 4410 2014-02-16 15:51 snow1 - 副本1Debugcl.command.1.tlog
文件 2 2014-02-16 15:51 snow1 - 副本1Debugli
文件 2 2014-02-16 15:51 snow1 - 副本1Debugli
文件 2 2014-02-16 15:51 snow1 - 副本1Debugli
文件 2 2014-02-16 15:51 snow1 - 副本1Debugli
文件 2 2014-02-16 15:51 snow1 - 副本1Debugli
文件 2 2014-02-16 15:51 snow1 - 副本1Debugli
文件 2 2014-02-16 15:51 snow1 - 副本1Debugli
文件 2 2014-02-16 15:51 snow1 - 副本1Debugli
文件 2 2014-02-16 15:51 snow1 - 副本1Debugli
文件 2 2014-02-16 15:51 snow1 - 副本1Debugli
文件 2 2014-02-16 15:51 snow1 - 副本1Debugli
文件 2 2014-02-16 15:51 snow1 - 副本1Debugli
文件 2 2014-02-16 15:51 snow1 - 副本1Debugli
............此处省略74个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)