# How to implement explosion in OpenGL with a particle effect?

I'm relatively new to OpenGL and I'm clueless how to implement explosion. So could anyone give me some ideas how to start? Suppose the explosion occurs at location $(x, y, z)$, then I'm thinking of randomly generate a collection of vectors with $(x, y, z)$ as origin, then draw some particle (glutSolidCube) which move along this vector for some period of time, says after 1000 updates, it disappear. Is this approach feasible? A minimal example would be greatly appreciated.

• If you're still using glutSolidCube, you aren't at the point where you should be making particle effects. – Nicol Bolas Oct 19 '12 at 19:34

You are on the right track.

Typically for particle effects, flat triangles or quads are used for the particles as opposed to something like glutSolidCube. Often the quad are billboarded so that they are always oriented to the camera (so you never see them edge on). Having said that, there is no reason why you can't use cubes for your particles (apart from performance)

The outline for a particle effect is something like this;

1. create a buch of particles, each particle will have its own velocity, position etc (see below)

2. each particle is drawn as a textured quad, usually blended, with transparent edges. The texture and colour of the quad depends on the effect you are trying to achieve.

3. When the particles are spawned at they explosion point,they will be launched out a random velocities, they will be initially very small, but are scaled larger over time. Usually each particle will also have some random angular velocity so the will also rotate as they move away from the spawn point.

4. As a particle grows older, at some point it will be forced to fade away, once it is are completely transparent they will be removed.

There are a lot of properties to control to get the effect you want

• range of initial velocities
• rate of spawning
• response to gravity & wind
• range of angular velocities