Particle Systems

When drawing particles, we often want them to "add up" in some way to form a fuzzy effect, rather than looking like just a set of individual points or lines.

This can be done using blending. Disabling depth-buffer-writing in this case is useful, because we don't want the particles to obscure each other.

    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ONE);
    glDepthMask(GL_FALSE);
    glBegin(GL_LINES);
    for (int i=0; i < numParticles_; i++)
        {
        glColor3fv(particles_[i].color.vec);
        glVertex3fv(particles_[i].tailPosition.vec);
        glVertex3fv(particles_[i].position.vec);
        }
    glEnd();
    glDepthMask(GL_TRUE);
    glBlendFunc(GL_ONE, GL_ZERO);
    glDisable(GL_BLEND);




Example:





next