Code:
void UpdateRain(void)
{
for (int i = 0; i < MAX_PARTICLES; i++)
{
int iRandX = ((rand()%500) - 250);
float dRandX = float(iRandX)/9;
int iRandZ = (rand()%500) - 250;
float dRandZ = (float)iRandZ/9;
int iRandLife = rand()%100;
float dRandLife = (float)iRandLife/100;
int iRandDeath = (rand()%10);
float dRandDeath = (float)iRandDeath/1000;
// Draw the particles using our RGB values
glColor4f(Rain[i].r,Rain[i].g,Rain[i].b,Rain[i].life);
Rain[i].xPos += Rain[i].xDir; //move on the x axis by x speed
Rain[i].yPos += Rain[i].yDir; //move on the y axis by y speed
Rain[i].zPos += Rain[i].zDir; //move on the z axis by z speed
Rain[i].life -= Rain[i].death; //reduce life by value of death
if (Rain[i].life < Rain[i].death)
{
Rain[i].xPos = dRandX;
Rain[i].yPos = 20;
Rain[i].zPos = dRandZ;
Rain[i].xDir = 0.01f;
Rain[i].yDir = -0.5f;
Rain[i].zDir = 0;
Rain[i].r = 0.90f;
Rain[i].g = 0.90f;
Rain[i].b = 1.0f;
Rain[i].life = dRandLife;
Rain[i].death = 0.01f;
Rain[i].speed = (float)(rand()%360);
Rain[i].angle = 160;
}
}
}
void DrawRain(void)
{
for (int i = 0; i < MAX_PARTICLES; i++)
{
glPushMatrix();
glTranslatef (Rain[i].xPos, Rain[i].yPos, Rain[i].zPos);
glDisable (GL_DEPTH_TEST);
glEnable (GL_BLEND);
glBlendFunc (GL_DST_COLOR, GL_ZERO);
glBindTexture (GL_TEXTURE_2D, myTexture[0]);
//glvertex3f determines particle size
glBegin (GL_QUADS);
glTexCoord2d (0, 0); //bottom left
glVertex3f (.05f, 0, 0.05f);
glTexCoord2d (1, 0); //bottom right
glVertex3f (.1f, 0, .1f);
glTexCoord2d (1, 1); //top right
glVertex3f (0.05f, .55f, 0.05f);
glTexCoord2d (0, 1); //top left
glVertex3f (0.05f, .5f, 0.05f);
glEnd();
glBlendFunc (GL_ONE, GL_ONE);
glBindTexture (GL_TEXTURE_2D, myTexture[1]);
glBegin (GL_QUADS);
glTexCoord2d (0, 0); //bottom left
glVertex3f (.05f, 0, 0.05f);
glTexCoord2d (1, 0); //bottom right
glVertex3f (.1f, 0, .1f);
glTexCoord2d (1, 1); //top right
glVertex3f (0.05f, .55f, 0.05f);
glTexCoord2d (0, 1); //top left
glVertex3f (0.05f, .5f, 0.05f);
glEnd();
glEnable(GL_DEPTH_TEST);
glPopMatrix();
}
}