How To: Create a Simple Fireworks Effect in OpenGL and SDL

I’m teaching the programming stream for Diploma in I.T. – Multimedia at the moment, so we’re going to be making some simple games and things over the next couple of months, but to start them off we’re doing a little bit of work on particle effects because they’re simple and fun – you just write a single class which describes the properties and behavior of your particle, and then scale it up by adding a large number of particles to get some pretty nice effects.

So instead of doing a particle fountain, I thought some fireworks might be kinda neat… Take a swiz at the video below and see what you think!

Full C++ source-code available after the break for those of a curious nature =D

Continue reading How To: Create a Simple Fireworks Effect in OpenGL and SDL

How To: Draw Motion-Blur/Trails using the Accumulation Buffer in OpenGL

I read that this is the slow/old-school/borderline-retarded way of going about adding motion blur to your scenes, but I haven’t started learning GLSL yet, so for the time being at least, this works :D

OpenGL Accumulation Buffer Motion-Blur/Trails

The trick is that you have to perform the following actions in this specific order in your drawing function for it to work:

  1. Clear the colour buffer (i.e. the screen) and the depth buffer (really, the colour buffer doesn’t need to be cleared because we’re over-writing it later, but the depth buffer definitely does!).
  2. Copy the accumulation buffer over the top of the colour buffer. (i.e. the contents of the colour buffer gets overwritten with the contents of the accumulation buffer).
  3. Clear the accumulation buffer.
  4. Draw your geometry.
  5. Copy the colour buffer onto the accumulation buffer. (i.e. the contents of the accumulation buffer gets overwritten with the contents of the colour buffer).

The relevant section of code from my drawScene() function is:

Note: See that </star> tag at the end of the above code snippet? That doesn’t exist. It’s an artifact produced by WordPress in combination with the WP-Syntax plugin and is somehow related (I think) to escaping HTML entities and auto-completion of mismatching XHTML. Don’t believe me? Click the title of the post or the read more link below and find the same section of code in the full listing – for some reason it doesn’t appear there… Odd, huh?

Update: Uploaded a screen capture of the program running to YouTube so you can see it in action without having to compile it yourself:

Full source-code available after the jump for those interested…

Continue reading How To: Draw Motion-Blur/Trails using the Accumulation Buffer in OpenGL