OpenGL gotcha: my particles are too small

As far as graphical effects go, a particle system is one of the most versatile. It can be used to simulate things like electrical sparks, dust clouds, smoke, fire, and water. However, there is one problem which I have been annoyed with several times in the past, but just lived-with because I didn’t think it important enough to fix.

I would spend ages programming a particle effect, tweaking all the parameters to get it just right, and it would look fine at first. But then, on another computer, or on a different screen resolution, or even just with a different size of window, the effect suddenly wouldn’t look right. All the particles would be too small or too big.

You can see this problem in the image above. It shows a particle effect for a rocket thruster — the one on the left is how it should look, while the one on the right shows what happened when I roughly tripled the size of the game window. Read more OpenGL gotcha: my particles are too small

OpenGL gotcha: remember GL_LIGHT0

In my experimenting with some simple scene geometry and lighting today, I stumbled into the same pitfall I’ve strumbled into several times before (you’d think I would have learned by now!). While moving around the scene, I found that the lighting on surfaces appeared to change depending on my camera angle — if I looked at a polygon square-on, it seemed much brighter than if I was looking slightly away from it.

There are two common reasons for this problem…
Read more OpenGL gotcha: remember GL_LIGHT0

OpenGL gotcha: remember light 0

In my experimenting with some simple scene geometry and lighting today, I stumbled into the same pitfall I’ve stumbled into several times before (you’d think I would have learned by now!). While moving around the scene, I found that the lighting on surfaces appeared to change depending on my camera angle — if I looked at a polygon square-on, it seemed much brighter than if I was looking slightly away from it.

There are two common reasons for this problem… Read more OpenGL gotcha: remember light 0

OpenGL gotcha: scale your normals!

My OpenGL blunder this evening involved forgetting to make sure my normals were scaled correctly.

I had a scene with a single point light source and several small rotating cubes. Everything looked fine. I had also written a function to draw a 1×1 plane in the scene, and that looked fine too. I then applied a scaling transformation in my plane-drawing function (using glScalef) to make it 10×10, but for some reason the plane was then totally dark.

I tried moving and rotating the plane to see if it would catch the light at some other angle, but it wouldn’t. Eventually, I spotted the flaw… Read more OpenGL gotcha: scale your normals!

OpenGL gotcha: depth buffer distortion

While I’m on the topic of OpenGL gotchas, I thought I’d mention another which caught me out a couple of years ago. I was working on some prototypes with some friends, and you can see a screenshot on the right (click it for a full view).

Notice areas where polygons overlap — you can see a striped or checked pattern of the occluded polygon showing through. In this case, it was 2d graphics and a 3d camera (so that we could make some interested visual effects). However, the problem manifests just as badly in full 3d.

It took quite a while to figure out the problem, and it’s one I’ll never forget. Read more OpenGL gotcha: depth buffer distortion