How-To: Create A Simple OpenGL 2D Particle Fountain in C++

I was recently asked about some particle systems I’d put together, so in response, this isn’t really a “look what I’ve coded” post – instead, it’s more of a “this is an easy way to set up a particle system framework” post.

To demonstrate the setup of a particle system using OpenGL, I’ve put together some simple starter code which displays a 2D particle fountain. I was going to just dump this code as a zipped project into a reply, but then (as my wife pointed out) it would be pretty much buried in the comments, so if other people starting OpenGL coding wanted to learn the basics of particle systems my code wouldn’t be as visible. As such, I’ve made this into a separate post – and all our example code does is this:

It’s a dirt-simple effect, but what it does isn’t so important right now – it’s deliberately simple. How it does what it does is what we’ll talk about.

Looking at particle systems from a high level – you generally have to choose between two different approaches to the system as a whole:

  1. You have a fixed number of particles (i.e. you have a fixed size array of however many particles) and you reset each particle to “recycle” it, or
  2. You have a dynamic number of particles (i.e. you have a dynamically resizable array) and you destroy each particle and create a new one as required.

I’ve gone with the latter approach for this code using a vector of particles (nothing to do with Vec2/Vec3 math – just the name of resizable array kinda construct). Admittedly, there’s more overhead in the creation and destruction of particles, but on the upside you don’t get that initial rush of particles you get when using fixed size arrays and as soon as you start the program BLAM! All your particles going at once.

To demonstrate what I mean, in the video below I’ve modified the code to instantiate ALL particles up to the particle limit at once, and then as soon as a particle goes off the bottom of the screen it gets destroyed and a new particle is created. The effect of which is that you get a single big burst of particles, and then as they all get destroyed and recreated at different times they turn into a smooth flow within a couple of seconds:

If you’re using a fixed size particle array, you’ll need to implement some mechanism to delay the instantiation or “launch” of the particles – for example, you might give each particle a random framesUntilLaunch value and decrease it by 1 each frame until it gets to 0 and you can let the particle do its thing. I wrote such a delay system for some fireworks code I did a while back if you’d like to see a concrete example.

Anyways, back at this code, our main is using three main classes to encapsulate data and provide methods to manipulate it:

  • Colour4f.hpp – A class to store a colour as red/green/blue/alpha floating point values and manipulate ’em (including interpolation of colours),
  • Vec2.hpp – A templatised class to store two values as a vector (Not a resizable array this time! An actually “euclidian vector” – i.e. two values which represent a direction and magnitude). It also includes lots of overloaded operators so you can add two vectors together (“up” + “right” gives you “up-right” etc.), multiply a vector by a scalar (i.e. moving “up-right” multiplied by 10 means you’re now moving up-right ten times as fast). By templatised, I mean that you can create a Vec2 of ints, or floats, or doubles, or shorts, or whatever numeric type makes sense for your application – take a look at the source below if you want examples, and finally
  • Particle2D.hpp – A particle class which uses the above Colour4f and Vec2 classes to provide powerful movement and colour modification options in a small & easy to use package.

You can download the complete source code as a Code::Blocks project here, if you’d like:

Note: As my OS of choice is GNU/Linux (LMDE, to be specific), the source files provided will have Linux line-endings – so you’ll need to open them with a good text editor like Notepad++ if you’re in in Windows, otherwise each file will look like a single massive block of noise!

Or, if you’d prefer to just browse the source code so you can copy and paste sections, you’ll find it all laid out below.

I love particle systems – you can do some visually stunning things with really simple code, or you can do amazing things if you take it further. Either way, I hope you have a lot of fun with them (there’s lots more particle stuff on this site if you’re looking for inspiration – try Actionscript tag for a start!) – and if you make anything cool or pretty using and you think I’ve helped – please do show me or let me know – I’ve love to see or hear about what you’ve done! =D

Also – if you make this – show me how, okay?


Continue reading How-To: Create A Simple OpenGL 2D Particle Fountain in C++

How To: Remove Adobe Drive

Adobe Drive is in the default install list for CS4, and even if you deselect it, you still end up with the explorer context entries for it, which point at absolutely nothing. As there’s no separate remove option for Adobe Drive, and I’m not using Version Cue servers, you need to find another way to get rid of said useless, space-occupying junk. Like this one…

On 32-Bit Windows:
Go to Start | Run… and enter:

Or on 64-Bit Windows:
Go to Start | Run… and enter:

This will unregister the Adobe Drive DLL and get rid of the context menus in one fell swoop…

If you (wisely) didn’t install it in the first place and just want to get rid of the context menu entries, fire up regedit and delete the following keys:

Job done.

Source: here.

How To: Install Thunderbird 3 in Linux

Update: In Ubuntu 10.04 Thunderbird 3 is now in the repositories so you can just install it through Synaptic or use sudo apt-get install thunderbird

Thunderbird is my email client of choice, but Thunderbird 2.x has some issues that bug me, like poor search facilities, no tabbed emails etc. so I want the next version with all its added goodness. However, Thunderbird 3 isn’t packaged in the Ubuntu repos yet, and I don’t feel like adding a PPA to my software sources (where Thunderbird is oddly branded as its project codename: Shredder) or waiting a couple of months until it’s available – so I’ve installed the new version manually and hooked it up to my Thunderbird 2 emails like this:

Thunderbird Logo

1.) Get Thunderbird 3 from

2.) Extract it by right-clicking on the file and selecting Extract Here, or from the console with something along the lines of:

Why xfvj? Because:
x = Extract
f = File mode (use the file listed on the command line)
v = Verbose (print a bunch of stuff to the screen so you can see what’s happening)
j = The file is compressed (you can tell because it’s called thunderbird-3.0.tar.bz2), so pipe it through bzip2 to decompress it first

3.) Copy it to a more reasonable location where you want it to live with:

4.) Sort out your email profile:

Thunderbird 2.0 uses the location ~/mozilla-thunderbird (i.e. a folder called .mozilla-thunderbird located in your home directory) to store your email, while Thunderbird 3 uses ~/.thunderbird, so when I did this I hedged my bets to make sure TB3 didn’t knacker the only copy of my email hive by creating a copy of the ~/.mozilla-thunderbird folder and renaming it to .thunderbird

5.) Create a launcher for our new Thunderbird install:

Assuming you’re using gnome, right-click on the top gnome panel and select Add to Panel, then select Custom Application Launcher and enter the following details:

Thunderbird 3 Launcher Details

6.) Launch Thunderbird 3 from your spiffy new launcher

Ch-Ching! New, emaily goodness is yours for the taking. You might want to uninstall Thunderbird 2 from Synaptic and nuke your old ~/.mozillia-thunderbird folder once everything’s up and running as it’s pretty unlikely you’ll ever be going back to an older version.

Shouts out to Parick Micka for his post which got me started, as the official Thunderbird install/upgrade instructions for linux – well, I couldn’t find them, and don’t know if they even exist.

How To: Fix a Separated Zip / Zipper

Do it like this lovely gentleman does do it:

But, heed this cautionary note from YouTube user Jammanen3; who so eloquently outlines a possible pitfall thus:

DON’T put that thing in the middle of the other thing. It broke my thing -.-. Use the thing on the sides of the sides of the other thing. That´╗┐ will work and hopefully not break the thing. :P Now I have to use some super glue to fix it -.-. Small pieces on the thing so it took me like 20 mins to fix it D:

Or in other words, don’t compress the top of the slider (the bit that actually meshes/unmeshes the teeth of the zip) with pliers, instead compress each side of the slider separately. Otherwise the piece of metal joining the pull-tab (take a wild guess..) to the slider can get mangled and come off, which you’ll then have to superglue back.

Fixed my shorts with a wonky zip double-fine :D

Although saying that, a few less pies and a bit more exercise and the zip wouldn’t have been knackered to begin with…