2014 Entity Systems: what are your Unity3D questions and problems?

In 2014, I’ll be making a new game in Unity that makes intensive use of an Entity System.

This will give me lots of ammo for a new post exploring the pros and cons of Unity’s “partial” Entity System architecture. I’ve been thinking about this a lot for the last couple of years, but I’ve been unhappy with the draft posts, and didn’t publish them.

Over the next couple of months, I’d love to hear from all of you the challenges, confusions, problems, and questions you have about this. I’m not promising quick answers – but it will help shape the blog posts I write, and as soon as I have a good enough set of answers, I’ll start posting them :).
Continue reading

OpenGL ES 2 – Textures 2 of 3: Texture Mapping

Recap: Texturing in OpenGL can be achieved in two separate ways, using different API’s and hardware features. The preferred, modern approach – procedural texturing – uses nothing more than a Fragment shader (this is really what Fragment shaders were created for: Texturing).

Part 5 (Textures: 1 of 3) covered that in detail – but there’s another option: Texture-Mapping (also known as “UV Mapping”, it’s identical).
Continue reading

GamesThatTeach: Conway’s Life, gamified…

Quick and simple conversion of Life into an actual game (instead of a mathematical “game”):


A couple of observations:

  • “Life” makes for a terrible game: it’s far too complicated to translate between “Thing I want to achieve” and “how I would choose/use/combine the pieces at hand to achieve it”
  • …Life using a library might work better, or Life with more human-friendly rules
  • Even in a simple form, the game aspects work quite well: you quickly start to learn *if you have a window open to Wikipedia or similar* how to remember and recreate the classic shapes

WordPress’s Akismet pushes Database to 30x real size

Like half the planet, I use WordPress as a blogging platform. There are many good things about it. One of those used to be Akismet (if you ignore the slightly unpleasant sales strategy: it’s free, if you give WordPress some personal details) – but today I hit a very serious bug in Akismet. I’ve had to delete Akismet – but WordPress’s coders don’t clean up after themselves, so you have to do some manual clean-up too. Read on.
Continue reading

Server overloaded by moronic spammers

I got an email this morning noting that my blog was taking “forever” to load a single post.

A quick check, and I found that it was running 70x overloaded, due to a vast number of spammers trying (and, in every case, failing) to submit wordpress comment-spam.

No spams will get through, because wordpress is set to only allow comments from people who’ve commented before – that’s a chicken-egg scenario that spammers can’t escape. (I wonder. Would the scourge that is “wordpress comment-spam” be reduced easily, instantly if Automattic (the people that make WordPress) had this as the default?).

…but at 2,000+ spammers a day, it was bringing the virtual site down. Server was fine, but I had the site limited precisely so that *it* would die instead of the server, in cases like this.

Now we’re going to try something new, since Automattic’s Akismet is pretty much useless these days. Anti-Spam, let’s see how you do…

Book: Game Development Principles (Alan Thorn)

I’ve recently been working with a group of teenagers, helping them learn to program for themselves, and build their own iPhone/iPad/Android games. So, when Cengage offered me a review copy of this book, I thought it would be a good idea to have a look and see if it would be helpful to a similar audience.

This blog isn’t a review site, so I’m going to pull out just the key interesting bits worth mentioning.

What’s the book for?

The blurb on the back cover claims:

  1. “games that enchant players and stand the test of time [are only made by people who know the] principles of good game design”
  2. “[this book has] the core theoretical knowledge”
  3. “math, textures, … geometry, … lighting, sound”
  4. “all your questions will be answered”

This book has nothing on game-design. There are few filler sections on this, but you’d get more detail by typing “game design blog” into Google and picking a link at random.

“Core theoretical knowledge” of game development is a big topic. If most people tried to write it down, I’d expect a thick, heavy tome. Thankfully, this book doesn’t try that. I’d say it aims for approximately 25% of the core knowledge, which is a reasonable compromise. Better to do some of it well, than do all of it badly.

On those named details:

  • “math” can’t be covered in a book unless that’s 50% of your content. This book has basic vector-math (really basic: not enough for game development), and quickly moves on.
  • “textures” skips all the bits about implementing textures, and instead focusses on issues to do with authoring simple 2D textures.
  • “geometry” only talks about things that 3D artists need to know when making models, it misses out all the things at the engine level, at design time, etc.
  • “lighting” is covered well, with a good explanation of deferred lighting (which is one of the major modern issues in lighting and 3D engines). More on this later
  • “sound” has basic info on implementing and playing-back sounds in-game.

In conclusion: the blurb on the cover is about 30% accurate. The book covers both more and less than it claims. On the face of it, this looks bad – but I think the book has rather more important/better content than the marketing claims

Continue reading

SVGKit: Programmatic editing of SVG files on iOS

(this is a post mainly to document some new features and fixes I’ve added to SVGKit version 1.2 today – they are already on the main development branch (currently: 1.x), ready for use)

SVGKit overview, November 2013

While a group of us were cleaning up and improving SVGKit about 2 years ago, I did a quick-n-simple re-architect of the in-memory data structures to split it into three wholly independent sets of source code / classes:

  1. Parsing an SVG file
    1. Parsing a legal XML file, with a new conforming DOM parser I wrote from scratch (because SVG Spec requires you to use a DOM parser, and Apple won’t let you use/extend their one on iOS/OSX!)
    2. Parsing the core SVG spec where it differs from XML-DOM
    3. Adding a system for user-supplied custom-parsers so that you can parse your custom XML in-line with the SVG (this is a major feature of SVG, but difficult to parse!)
  2. Rendering an SVG file with pixels on-screen
    1. Converting in-memory SVG data into Apple’s CALayer rendering format (used on all Apple Operating Systems)
    2. Optionally converting Apple’s CALayer format into highly-optimized hybrid data that lets you render SVG’s *fast*
    3. Painstakingly implementing every feature of SVG, from radial gradients to rich text (we’re about 90% complete now, still features left to add – please help!)
  3. Outputting an SVG file back to disk
    1. …not supported … until now!

Continue reading

OpenGL dumb mistakes: the mysterious Perfect Circular Hole

I’ve got a long-running project around rendering 3D Earth in interesting ways. It’s being used in a game project, and some non-game stuff too. Here’s a recent screenshot:

I added a particle system that uses Vector Fields to move the particles based on arbitrary incoming data, and then wraps it round a globe. Yay!:

…and then I increased the size of each particle, and something very strange happened. I wanted to splurge them out to be huge, but

The mysterious Holes Of Doom

… these weird holes appeared in the middle:

WTF? I must have done something stupid. I double checked everything. I removed the textures. I switched from quads to basic tris, with vertex colours … but still, this perfect circle cut out of the center! My vertex and fragment shaders by this point were exactly one line of code!

…I spent ages looking at this, trying to understand what could possibly create “holes” in my geometry. They were obviously holes – you can see through them!

Eventually, tired, and with lots of more important work to do, I gave up, shelved it, went off to do other things. Then today I suddenly realised the problem. I’m sure it’s obvious to most of you, but it’s taken me ages to figure it out.

When a hole is not a hole

And this is what makes it worth posting: the hole is not a hole.

My particles are on a 2D plane, so that I can calculate simple x/y coords from a vector-field. Great. My shader wraps the corners to a sphere. I’m rendering quads / tris like this:


Great. But GL doesn’t “bend” the edges – it draws straight lines between corners. So … when I made my tris larger … the corners were still slightly above the surface of the globe.

…and the EDGES were still slightly above

…but the centers … slightly interesected the globe. And so, of course, the depth-test cut them out. In the diagram below, it looks as if the quad moved closer to the center of the globe – but it hasn’t. The corners are all still the same height above the surface – only the middle has (implicitly) gone “inwards”.


Lesson to self: sometimes, it’s not a triangle-with-a-hole-that-I-can-see-through … instead, it’s a triangle-that-has-a-sphere-poking-through-the-middle


What programming language should aspiring game developers learn in their free time?

I was asked this recently in private mail by someone heading off to University / College. For people choosing between a Computer Science/Software Engineering course vs. a Game Design / Game Development course, I’d said:

If you love games, you’ll do both anyway; one you’ll learn in lectures, the other you’ll self-teach. Which will you find easier to self-teach (given no-one is prodding you), and which will you need the extra benefit of having a formal course/teaching/teachers? (usually: people find it easier to self-teach “designing and making my own game experiments”. Usually, people find formal Computer Science / Maths is ‘hard’, and they need the help of a formal course)

Gross generalization: Most game-developers in the indie community are programmers; most of them are programmer-centric when looking at the world. I’m a programmer, but I’ve done approx 40% of my career in project-management and studio management (and even a tiny bit of publishing) over the years.

There’s one interesting point I want to clarify a little: By “indie community” I mean “focussing on the places filled with people who actually ship games”. Most game designers who want to make their own stuff have to learn programming, even if they’re 100% non-programmers, since it’s the only way to get “your” vision launched. Even the ones that started-off as pure artists often end up being highly technical (whether they admit that to themselves or not).

So … this is not a popular view, but I think it’s more accurate than most: by the time you finish a 3-4 year course starting “today” … C++ won’t be the game-dev language people care about. Already, for entry-level jobs most studios are more interested in “how good are you at Unity? How good’s your C#?”. That trend will only continue/increase.
Continue reading

iOS Open GL ES 2: Multiple objects at once


  1. Part 1 – Overview of GLKit
  2. Part 2 – Drawcalls, and how OpenGL code is architected
  3. Part 3 – Vertices, Shaders and Geometry
  4. Part 4 – (additions to Part 3); preparing for Textures

…but looking back, I’m really unhappy with Part 4. Xcode5 invalidates almost 30% of it, and the remainder wasn’t practical – it was code-cleanup.

So, I’m going to try again, and do it better this time. This replaces my previous Part 4 – call it “4b”.

Drawing multiple 2D / 3D objects

A natural way to “draw things” is to maintain a list of what you want to draw, and then – when the OS / windowing library / whatever is ready to draw, you iterate over your “things” something like:
Continue reading

OpenGL ES 2 for iOS: glDebugging and cleaning-up our VBOs, VAOs, and Draw calls

UPDATE: This post sucks; it has some useful bits about setting up a breakpoint in the Xcode debugger – but apart from that: I recommend skipping it and going straight to Part 4b instead, which explains things much better.

This is Part 4, and explains how to debug in OpenGL, as well as improving some of the reusable code we’ve been using (Part 1 has an index of all the parts, Part 3 covered Geometry).

Last time, I said we’d go straight to Textures – but I realised we need a quick TIME OUT! to cover some code-cleanup, and explain in detail some bits I glossed-over previously. This post will be a short one, I promise – but it’s the kind of stuff you’ll probably want to bookmark and come back to later, whenever you get stuck on other parts of your OpenGL code.

Cleanup: VAOs, VBOs, and Draw calls

In the previous part, I deliberately avoided going into detail on VAO (Vertex Array Objects) vs. VBO (Vertex Buffer Objects) – it’s a confusing topic, and (as I demonstrated) you only need 5 lines of code in total to use them correctly! Most of the tutorials I’ve read on GL ES 2 were simply … wrong … when it came to using VAO/VBO. Fortunately, I had enough experience of Desktop GL to skip around that – and I get the impression a lot of GL programmers do the same.

Let’s get this clear, and correct…
Continue reading

Why is a Fragment Shader named a Fragment Shader?

I’m writing some KISS tutorials on using OpenGL ES 2.0 in iOS/mobile, because I was frustrated that most of the tutorials on GL ES used incorrect or outdated approaches.

(I’m using the OpenGL ES 2.0 Programming Guide as my baseline, along with my own experiences of game-programming, and checking it all against Khronos Group / OpenGL.org’s docs as I go)

I use this stuff in iOS apps, but … I’m a relative novice with shader-pipelines. So I’ve been leaning on the guys at The Chaos Engine for proofreading and to help me avoid spreading misinformation. Most stuff people broadly agree on, but there’s been some interesting debate over a seemingly trivial question:

Why does OpenGL use the term “Fragment Shaders” to describe the shaders-that-generate-pixels? (where other API’s call the same thing “Pixel Shaders”, a much easier to understand/remember name)

Continue reading

Installing HMRC’s PAYE tools on OS X

The old PAYE tools was bad, really bad – I saw it generate the wrong figures once (i.e. actively costing UK small businesses real money for HMRC’s carelessness).

The new one is great – but it hasn’t been tested properly. The install instructions are wrong, it installs illegally on OS X, and it has a major bug in the configuration system. By accident, I discovered it’s all written in Python, which I find very interesting although currently it’s a bad advert for the language :(.

Here’s how I fixed it…
Continue reading

Fixing Firefox: removing the bad new-tab window (AGAIN!)

We already had to do this a year or so ago when Firefox developers tried to force a bad UI paradigm on us.

Now they’ve done it again, and added a new way to turn “new tab” from something that does what it says, into something that does stuff you don’t want.

Turn it off by pressing the magic button that exists nowhere else in Firefox and which you’d never guess was related to this broken feature.

OpenGL ES 2: Basic Drawing

UPDATED 24/09/13: Added some essential details to the class files at end of post, and corrected typos

UPDATED 24/09/13: Added Github project with full source from this article

This is Part 2. Part 1 was an overview of where Apple’s GLKit helps with OpenGL ES setup and rendering.

I’ve been using OpenGL ES 2 less than a year, so if you see anything odd here, I’m probably wrong. Might be a mix-up with desktop OpenGL, or just a typo. Comment/ask if you’re not sure.
Continue reading