Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I want to implement a particle system in my game, but I've never programmed a particle system and don't know where to start.

I only want to display pixels (GL_POINTs) with different sizes in different places, something like Terraria or Minecraft when you hit a block, without the texture. Just a dead simple example.

Google search results for this tend to be very complex, or don't explain the concepts, or are written in hard-to-read C without OOP…

I'm using Java and OpenGL.

share|improve this question

1 Answer 1

up vote 8 down vote accepted

I think the key phrase is particle system so most of the samples out in the wild are going to be more complex than you would think a simple demonstration should be. OOP doesn't really enter into the low level part of particle systems and C is very straight forward to convert to other languages so I wouldn't worry about that.

The trick to particles is that you want to display a LOT and as fast as possible, that colors the kinds of code you'll see since everything is optimized in one way or another.

In its simplest form a particle system for a quick splash effect would have the following elements:

0) a manager both to keep track of all your systems and to give global control to all effects 1) array of "points" where each has position, velocity, life time, display size 2) a function to create that array with a starting position and (probably) random velocities and life times 3) a function to run a simulation on that array, this probably takes a delta time since the last simulation call 4) a function to take the positions and display sizes and display then in OpenGL 5) and lastly an overseer to stop that system from playing when all the points are dead

Organizing the functions can be OOP at the higher levels as long as the inner loops keep to themselves in the quest for speed. Super lax pseudo code sequence below, leaving out a lot of detail and mixing and matching straight C concepts with a cheesy OOP thrown in but I hope it makes sense. The class design for this would be an entire other discussion =)

For your example, you hit a brick at world location (10,20,30). You then call the manager and ask it to start up a new points particle system at that location. The manager then asks the PointsClass to create itself at position (10,20,30). The class allocates and randomizes the life times, etc... The manager then calls all the active particle systems it controls each frame with a simulation call. Later that frame it asks the PointsClass to draw itself into a GL context. Loop until done.

share|improve this answer
Thank you for your post! Now I have clear ideas about this. I think I'll give a break to NeHe tutorial about particle systems. –  Puyover Jul 17 '11 at 0:05
NeHe is a great place, you won't go wrong there! Best of luck. –  Patrick Hughes Jul 17 '11 at 0:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.