资源简介

在vs2010环境下 用opengl以及粒子系统思想做的一个简单的雪效 里面还涉及到alpha混合来进行雪粒子的纹理贴图

资源截图

代码片段和文件信息

#include 
#include 
#include 
#include 
#include 
#include “Texture.h“

#define PARTICLE_NUMBER 1000
GLuint texture[2];
typedef struct
{
GLfloat xy;
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-90.0;
particles[i].y=150;
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(1.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(“snowflower.jpg“texture[1]);
}

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(-130.0-120.0-1.0);
glTexCoord2f(10);glVertex3f(130.0-120.0-1.0);
glTexCoord2f(11);glVertex3f(130.0120.0-1.0);
glTexCoord2f(01);glVertex3f(-130.0120.0-1.0);
glEnd();
glDisable(GL_TEXTURE_2D);

for (int i=0;i {
if(particles[i].life>0)
{
glPushMatrix();
// glTranslatef(particles[i].xparticles[i].y0.0);
//  GLUquadricObj *qobj;
//  qobj =  gluNewQuadric();  
//  gluDisk(qobj0particles[i].r101);
glEnable(GL_TEXTURE_2D);
    glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBindTexture(GL_TEXTURE_2Dtexture[1]);
glBegin(GL_QUADS);
glTexCoord2f(00);glVertex3f(particles[i].x-particles[i].rparticles[i].y-particles[i].r0.0);
glTexCoord2f(10);glVertex3f(particles[i].x+particles[i].rparticles[i].y-particles[i].r0.0);
glTexCoord2f(11);glVertex3f(particles[i].x+particles[i].rparticles[i].y+particles[i].r0.0);
glTexCoord2f(01);glVertex3f(particles[i].x-particles[i].rparticles[i].y+particles[i].r0.0);
glEnd();
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glPopMatrix();
particles[i].life-=float(rand()%100)/1000.0f+0.0003f;
particles[i].y+=particles[i].vy;
particles[i].x+=particles[i].vx;
particles[i].vy+=particles[i].ay;
particles[i].vx+=particles[i].ax;
}
if(particles[i].life<=0)
{
particles[i].life=rand()%200;
particles[i].r=rand()%3+1;
particles[i].x=rand()%250-90.0;
particles[i].y=150;
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;
}
}
glFlush();
glutSwapBuffers();
}

void reshape(GLsizei wGLsizei h)
{
glViewport(00wh);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0(GLflo

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-12-29 20:30  1\
     目录           0  2013-12-29 20:30  1\1\
     文件        3460  2013-12-29 19:35  1\1\1.cpp
     文件        4115  2013-12-23 11:13  1\1\1.vcxproj
     文件        1167  2013-12-23 11:13  1\1\1.vcxproj.filters
     文件         143  2013-12-23 11:04  1\1\1.vcxproj.user
     目录           0  2013-12-29 20:30  1\1\Debug\
     文件         406  2013-12-23 11:05  1\1\Debug\1.exe.embed.manifest
     文件         472  2013-12-23 11:05  1\1\Debug\1.exe.embed.manifest.res
     文件         381  2013-12-29 19:34  1\1\Debug\1.exe.intermediate.manifest
     文件          90  2013-12-29 19:34  1\1\Debug\1.lastbuildstate
     文件        2137  2013-12-29 19:34  1\1\Debug\1.log
     文件       37099  2013-12-29 19:34  1\1\Debug\1.obj
     文件         192  2013-12-23 11:05  1\1\Debug\1_manifest.rc
     文件       26938  2013-12-29 19:34  1\1\Debug\CL.read.1.tlog
     文件        1414  2013-12-29 19:34  1\1\Debug\CL.write.1.tlog
     文件       40337  2013-12-23 11:13  1\1\Debug\Texture.obj
     文件        1434  2013-12-29 19:34  1\1\Debug\cl.command.1.tlog
     文件           2  2013-12-29 19:34  1\1\Debug\link-cvtres.read.1.tlog
     文件           2  2013-12-29 19:34  1\1\Debug\link-cvtres.write.1.tlog
     文件           2  2013-12-29 19:34  1\1\Debug\link.12336-cvtres.read.1.tlog
     文件           2  2013-12-29 19:34  1\1\Debug\link.12336-cvtres.write.1.tlog
     文件           2  2013-12-29 19:34  1\1\Debug\link.12336.read.1.tlog
     文件           2  2013-12-29 19:34  1\1\Debug\link.12336.write.1.tlog
     文件           2  2013-12-29 19:34  1\1\Debug\link.12576-cvtres.read.1.tlog
     文件           2  2013-12-29 19:34  1\1\Debug\link.12576-cvtres.write.1.tlog
     文件           2  2013-12-29 19:34  1\1\Debug\link.12576.read.1.tlog
     文件           2  2013-12-29 19:34  1\1\Debug\link.12576.write.1.tlog
     文件           2  2013-12-29 19:34  1\1\Debug\link.3704-cvtres.read.1.tlog
     文件           2  2013-12-29 19:34  1\1\Debug\link.3704-cvtres.write.1.tlog
     文件           2  2013-12-29 19:34  1\1\Debug\link.3704.read.1.tlog
............此处省略54个文件信息

评论

共有 条评论