/* You are not expected to understand this. */

Shaders 101

Posted: July 23rd, 2011 | Author: | Filed under: Tutorials | No Comments »

As indie or casual game developers, we seldom get the chance to play with shaders. The reason why is that there simply is no need to get ourselves involved in all that “stuff”. The engines that we work with come with most of the stock shaders that we need, so all that is required is a basic understanding of what they are and what they do. Kind of like suntan lotion, you don’t question too deeply how it works. You just slap it on.

Recently however, I have had the occasion to dabble in shaders and found that it is really not all that complicated. So here’s a little overview to get you started.

The Triumvirate

Some time ago, shaders were written purely in assembly, much like how normal programs were written a longer time ago. The next natural step in evolution was of course to spawn a set of high level languages to deal with the complexity. HLSL was coined by the folks at Microsoft. It works in tandem with DirectX, meaning it’ll run cross-platform as long as by cross-platform, you mean Windows and Xbox. GLSL was spawned by the hippie open-source community and works as a direct extension of OpenGL, so it will run everywhere else. The folks at NVidia came up with CG which doesn’t really run anywhere but instead compiles into both HLSL and GLSL, presumably saving time writing shaders in both languages.

Structurally, they are all the same. It is only a matter of syntax and code rearrangement, if you ignore some of the more esoteric features of each language. All of them give you the power to manipulate matrices and vectors as easily as you would mere integers in traditional programming. They are also designed to be (potentially at least) massively parallel so more things can be done faster, which is generally a good thing. The price, however, is limitations in what you can actually do within your shader.

The Pipeline

The programmable pipeline as they like to call it, differentiates itself from the more traditional fixed pipeline in the sense that it is, well, programmable. This gives the programmer (or artist, if the dirth of shader generation tools keep growing) more power over the rendering process.

The old way of doing things was that you’d fill up vertex buffers with vertices, index bufferes with indices, strategically position a few lights and define a few global parameters. After you have everything configured sweetly, hey presto, there’s your pretty picture! The main errors students commit using this traditional workflow are trivial things like… do you have a light in the scene? Is your camera pointed the right way? Is the object so small that it is occupying less than one pixel on screen? Ahh… life was simple back then!

Nowadays, you start of with a set of vertices. These could come directly from meshes or they could be generated from geometry shaders (I don’t know much about geometry shaders so I’m not going to say much about them). It doesn’t matter. Each and every vertex gets run through your vertex shader program. This happens four, eight or however many channels your graphics card has, at a time. As a result, you  can’t get information on the other vertices (unless you are especially clever and sneaky about it), but you can pretty much do whatever you want with the vertex you have. Change its position, its color, its normal or any other of its attributes. Totally up to you. Of course, with great power comes great responsibility, and with great responsibility comes greater potential to f*** things up.

Once all the vertex processing is done, your vertices get rasterized. Usually, by that, we mean that they get transformed to 2D screen coordinates, but that isn’t exactly true. It is the job of your vertex shader to transform the vertices into 2D coordinates (it’s just a matrix multiplication, not hard). What the rasterizer does is it goes through the pixels between your vertices and interpolates the values. So if you have one vertex that is red and another that is white, all the pixels in between will be varying shades of pink. This doesn’t just happen for your colors, but also for normals and whatever other attributes you may have chosen to endow your vertices with.

Each of these pixels is then fed into your pixel (if you are from Microsoft) or fragment (if you are a hippie) shader for further processing. There, you can do a whole bunch of other complex or simple operations, simply to figure out what color you want to paint that particular pixel. As per your vertex shader, you only have access to that one pixel throughout your shader, and the pixels themselves get pushed through n channels at a time, depending on how much your vendor crippled your graphics card via firmware.

Shader Anatomy

Finally we get to the code part of things. I’m going to compare CG and GLSL, mainly because CG and HLSL code look pretty similar, and CG has less letters.

Data types

There are four general data types to be found in a shader language.

  • There’s the basic floating point number, which all three languages have aptly named “float”.
  • There’s the vector of varying sizes, called float2, float3 and float4 in CG, or vec2, vec3 and vec4 in GLSL
  • There’s the matrix of varying sizes, called float2x2, float3x3, float4x4 in CG and mat2, mat3 and mat4 in GLSL
  • There are textures of varying dimensions, called texture2D, texture3D and texture4D in CG and sampler2D, sampler3D and sampler4D in GLSL (don’t let 4D textures blow your mind!) These are essentially the equivalent of lookup tables.

Of course, there are a lot more actual data types than these, most having to do with fixed-point math or irregularly shaped matrices. You also have bools and stuff, but you can figure those out on your own.

Types of Variables

As you may or may not have gathered from the section on pipelines, much of the idea behind shaders is about data flow and how it trickles down into the pixels. As a result, we have four types of data.

Uniform variables are stuff that you just sorta shove into the shader. How they get in is up to you. Some have them as part of the exporter from Max or Maya. Some have them built into the level editor. As long as you feed your shader before you run it, all will be well. Here’s your world matrix, a handful of numbers that should mean something and a few vectors for good measure. glhf! CG embraces the evil and defines these as simply global variables within the shader code. GLSL is more circumspect and demands that you use the keyword “uniform” to denote them. GLSL also has a whole bunch of predefined uniform variables just to keep everybody on the same page.

float time;
float amplitude;
float frequency;
float ambient;
float4 lightdir;
texture2D tex0;
uniform float time;
uniform float amplitude;
uniform float frequency;
uniform float ambient;
uniform vec4 lightdir;
uniform sampler2D tex0;

Uniform variables aren’t your only form of inputs. There are also vertex attributes. These are attributes that are defined as part of your vertex data structure. They can include mundane things like color, normals and uv coordinates, as well as customized data that only has significance to your skillfully crafted shader. How do you generate these vertex attributes? They can either be pre-calculated, or more often than not, are “painted” in by the 3D artist.

struct a2v
float4 position : POSITION;
float4 color : COLOR0;
float4 normal : NORMAL;
float2 texcoord: TEXCOORD0;
//attribute vec4 gl_Vertex already defined
//attribute vec4 gl_Color already defined
//attribute vec4 gl_Normal already defined
//attribute vec2 gl_MultiTexCoord0 already defined

In CG, all you do is define a struct and dump whatever vertex information you want into it. This will later be fed into your vertex shader. You can call your attributes whatever you like, but may need to tag them for deciphering purposes. For GLSL, you use the keyword “varying”. Like uniform variables, GLSL has a lot of predefined vertex attributes to cover the usual suspects.

Varying variables are what your vertex shader spits out, and is then fed into your pixel/fragment shader. Remember that by the time they reach the pixel shader, you will more often than not be working on interpolated data. In CG, you define another struct to hold this intermediate information. In GLSL, you use the keyword “varying”. As always, there are a bunch of predefined varying variables.

struct v2p
float4 position : POSITION
float4 color : COLOR0;
float4 normal : NORMAL;
float2 texcoord : TEXCOORD0
//varying vec4 gl_Position already defined
//varying vec4 gl_FrontColor already defined
varying vec4 normal;
//varying vec2 gl_TexCoord0 already defined


Finally, you have the output from your pixel shader. In CG this is, you guessed it, another struct. In GLSL, there’s no keyword. You just use the predefined variables, namely gl_FragColor.

struct p2f
float4 color : COLOR0;
// gl_FragColor already defined

The Shader Functions

After you have defined the data that you are going to be playing with, all that is left is to write the shaders themselves. Each shader is a self-contained function. In GLSL, your vertex and fragment shaders are usually in different files, and the entry point for each one is called “main()”. For CG, however, you can have multiple shaders in the same file and call them whatever you want. Whatever the case, during the actual render process, one program, comprising of exactly one vertex shader and one pixel shader, will be run per mesh per pass.

Here is a vertex shader that bounces the mesh around a bit.

v2p mainV(a2v IN)
v2p OUT;
OUT.normal = IN.normal;
OUT.color = IN.color;
OUT.position = IN.position + amplitude * sin(time*frequency);
OUT.texcoord = IN.texcoord;
return OUT;
void main()
normal = gl_Normal;
gl_FrontColor = gl_Color;
vec4 newpos = gl_Vertex + amplitude * sin(time * frequency);
gl_Position = gl_ModelViewProjectionMatrix * newpos;
gl_TexCoord0 = gl_MultiTexCoord0;

And here’s a pixel shader that computes lighting and figures out what color to render based on the supplied texture, vertex color, directional light and ambient lighting. Note that it would have been more efficient to calculate the texture color as well as lighting in the vertex shader rather than here, so that it is calculated per vertex rather than per pixel. Food for thought… think of all the neat hacks you can do! Also think of all the side-effects!

p2f mainF(v2p IN)
p2f OUT;
float NdotL = dot(IN.normal, lightdir);
OUT.color = IN.color * tex2D(tex0, IN.texcoord) * NdotL + ambient;
return OUT;
void main()
float NdotL = dot(normal, lightdir);
gl_FragColor = gl_FrontColor * texture2D(tex0, gl_TexCoord0) * NdotL + ambient;


The Move to Sheepland

Posted: June 18th, 2011 | Author: | Filed under: Soapbox | 2 Comments »

So e-Goh, the carefree freelance game developer is no more, having crossed over to the dark side of corporate game development with Gameloft, Auckland. Why would I want to make such a move? First, adventure (i.e. get into trouble). Second, to get out of Singapore. Lastly and mostly, it sounded like fun!

The Application

How does one get a job with a large game development studio that is located overseas? Quite simply, you apply. I sent out my resume to anybody with an email address. Most useful were the contacts I gained through LinkedIn and Facebook. Pretty much none of them replied. Big studio, small studio, it didn’t matter, and it was expected. That is the way the world is, you can’t just send out your resume and hope for the best. Instead, you have to relocate first, get to know the companies there, and then apply!

Well, apparently Gameloft didn’t get the memo. They replied! They sent me a test to do, which I apparently aced (of course), and then we had a quick interview over the telephone. Just like that, “Wham! Bam! Thank you Ma’am!”, I was in!

The Process

Just getting the job wasn’t enough. There’s still the process of actually getting into New Zealand. In order to work in New Zealand, you need a work visa, and they are pretty strict about it. Depending on the length of your stay, you may be required to go for a full medical checkup, get the CID to issue a police report to vouch for the goodness of your soul, and who knows what else? Fortunately, the length of my initial contract was only one year, so it wasn’t too much of a hassle.

On the employer’s side, they had to prove that they actively tried to look for talent in New Zealand and couldn’t find it. Luckily for me, they had already been searching since January last year and we had plenty of documentary proof. They also had to furnish documents like the offer letter, employment contract, etc. for the perusal of the immigration office (which is located in Ngee Ann City, if you’re curious).

After about 10 days, approval was obtained, and all that was left to do is procure tickets, hop on a plane and pray it wouldn’t crash.


It’s amazing what horror stories people tell you when you are about to move. The income tax is 30%! The public transport sucks! The streets are barren and empty, with nothing but sheep grazing around! The natives are racist and will murder you in your sleep!

All of the above, of course, is not true. But even the great man in the sky had his two cents. A month before I left, Christchurch (a major city on the south island of New Zealand) was hit by an earthquake. Barely a day after I arrived, he whacked it again. He also sent a giant volcanic ash cloud all the way across the Pacific Ocean, that had Qantas, Jetstar and other airlines grounding their planes. Luckily, I was travelling on Singapore Air, which isn’t put off by a little dirt in the air.

The Flight

No sign of an ash cloud!

As I stepped through the gates at Changi Airport, leaving my family behind, the enormity of what I was doing hit me. I had left on fairly long business trips before, but what I was doing now was starting a new life in an unknown country where I don’t know a single soul. (which was kind of the point of it all) Not being the religious type, I didn’t ask for a divine sign. However, I got it anyway. As I stepped into the departure lounge, I was greeted by oodles and oodles of japanese school girls! Surely this boded well for the trip ahead. Unfortunately, they were put in a separate part of the plane.

The flight from Singapore to New Zealand takes 9.5 hours. That’s a lot of time to spend cooped up on a plane. Fortunately, I was on a night flight, so I slept through most of it. The in-flight entertainment movies were meh. I only watched the Green Hornet. I really loved my Shure e2c earphones as they managed to block out a great deal of the engine noise, as well as all of the chatter and baby sounds.

When I arrived at Auckland International Airport, the first thing I did was grab a pre-paid SIM card from Vodaphone, complete with 50 MB of 3G data. I figured that as long as I have Google Maps, there should be no problem! After that was the trip to what I now affectionally call…

The Housing Debacle


I arrived at Lantana Lodge, to be greeted by a very cheerful Japanese guy. He looked up my reservation and exclaimed, “Wow, you have the luxury room!” Sounds good right?

Well it turns out that Lantana Lodge is a hostel, with about 30 people (at the time) living together. My “luxury room”, was a double bed and a mini fridge in a room. That was all. No bathroom, no wardrobe. The toilet facilities were communal, as was a general rec lounge and kitchen. Too tired to complain, I crashed to bed (which was incidentally very high quality, especially compared to everything else) and slept till about 7 when I snuck out for a kebab dinner before getting myself organized.

It was lucky that I slept in the afternoon, because at 3am, band practice was in full swing, replete with drums, guitar and singing. Unfortunately, they weren’t very good.

After one night there, and much complaining, I was transferred to Quality Hotel Barrycourt, which was the polar opposite from Lantana Lodge. This was a full-fledged hotel. So from communal toilets, I progressed to a private bathtub with full toiletries provided. I also got a kettle with free coffee, a 32″ flatscreen TV, and an ironing board. The food at the restaurant was also pretty good.

This weekend, I have been shifted once more, this time to 45A, St Georges Bay Road. This is a small 2-bedroom townhouse which I am sharing with a young English couple who are also here for work (but for a different company). So now I have a full kitchen, living room with TV and comfy leather sofas, and pretty much everything you would expect to have in a house. I may opt to continue staying here (at my own expense this time), but on Monday, I will be viewing a studio apartment in town which I may move into.

Much better accommodations!

Culture Shock

I was expecting things to be different in New Zealand, but it’s a bit hard to predict exactly how that manifests. The big shot to the liver of any game developer is that the Internet is rationed! All the internet plans have a set amount of  data which you are allowed, after which you must either top it up or proceed at excruciatingly slow speeds. That puts a severe cramp on how many games you can purchase of Steam. Bit Torrent and the likes is of course, completely out of the question, not that I ever indulged!

Kiwis don’t carry much cash in their wallets. Almost every transaction, even ones as small as a couple of dollars, are done with the swipe of an Eftpos card, which is something like a debit card. The only time when you use actual physical cash is for bus rides, and even then, there are stored value cards much like what we have in Singapore. New Zealand is well on the way to becoming a paper-cashless society.

Another peculiarity is that we don’t like color here. Indeed, on the streets, all you see is blacks, greys, dark blues and the occasional olive drab. Perhaps this is in support of the All Blacks? Whatever the case, it made my bright cyan ski jacket stick out like a sore thumb. So one of the first few things I bought here was a nice black leather jacket. The leather’s so soft and keeps me very warm, occasionally too much so when the sun is shining. I’ll probably look for a hoodie as well, because that’s what all the Starcraft pros wear!

The weather is decidedly mild, with temperatures between 12 and 17 degrees Celsius. It is winter now, and that means rain. When I say rain, it’s not the torrents like we have in Singapore, but very mild drizzles. One night, I made the fatal error of carrying an umbrella. While the raindrops themselves are very light, the wind is crazy! It was a major task just getting the brolly to behave. No wonder everybody else would rather walk in the rain!

The Workplace

The Gameloft office is pretty big, spanning two floors. It follows the japanese layout, i.e. everybody in an open space, no cubicles and no rooms. I’ve been given a pretty sweet rig, i7 processor, double monitors, etc. My programming lead a pretty cool fellow. We had the following conversation:

“So, have you done game programming before?”

“Yes, for about seven years.”

“OH YES!!! Thank you!!!”

They are evidently facing the same labour problems we have in Singapore, possibly more acutely. The only major gaming companies here in Auckland are Gameloft and Sidhe, so the industry still has a ways to develop. I searched for a local IGDA chapter. I ended up finding NZGDA, where I read the following forum post, “New Zealand is a bit slow. Things will pick up in 10-15 years”. Oh my!

That being said, I managed to find the “underground indie game developer” group that meets up monthly. Maybe I can get some good networking action there! Some guy from Zynga is supposed to be coming to give a talk on the 26th.

Where to go from here?

Well, first I need to find permanent accommodations, and get my sleep cycle sorted. After that, and my initial 360° exploration of the surroundings, I can finally settle down and perhaps get some work done on Darwena, which as been languishing in the sidelines for way too long. I’ll also be looking around for new activities. I found a quaint little coffee shop on Parnell Road (an old part of town) which would be excellent for an afternoon of coding. Things are looking up indeed!


Job-Seeking In The Game Industry

Posted: April 10th, 2011 | Author: | Filed under: Soapbox | No Comments »
Interested in a Job?

Interested in a Job?

With my recent foray into realm of job-seeking, it seems I have come full-circle and experienced all sides of the interviewing table. I have been an educator, a contractor / freelancer, recruiter  and now a job-seeker. Yes, the table is indeed rectangular as all good and proper tables should be. (Don’t believe any of that round table nonsense!) I figured I might as well write on each of these perspectives to provide you a more holistic picture. Happiness and satisfaction, however, are not guaranteed.

The Educator


How many game industry veterans do we have in Singapore that are willing to lend their wisdom? The answer is zero. So who are teaching these game courses? There are three main types. The first is the educator that is not from the games industry. They basically read a lot of books, try to get the gist of what it’s all about, and do their best to pass it on to the students. This group was especially prevalent six years back when these game courses were just starting to emerge.

The second group is your imported talent. Experts you bring in from overseas to train the local younglings. I am guessing that they are pretty expensive, and you would tend to see them more in degree courses than diploma ones. I do not know the mettle of these foreign talents, never having the chance to be under the tutelage of one. I would expect them to be above average given the credentials I have been seeing.

Lastly, you have the half-baked potatoes. This is the group I belong to. Sure, we have some experience, but wouldn’t call ourselves experts by any measure of the word. We are simply the only locally available alternative. There are a bunch of us roaming about between the institutions, and most teach on a part-time basis to supplement our other work. Oh, wouldn’t it be wonderful if we had retirees like say, Miyamoto, to spread their wisdom.


Right, teachers are a problem. The next problem is students. Unfortunately, the words “game development” are so interesting that we attract quite a crowd, most of whom are more interested in the “game” part than the “development” part. The other sad thing is that these students are under the impression that once they graduate and have their fancy piece of paper, they are industry-ready. The sad truth is that you are only really ready if you are self-motivated enough to pick up skills on your own. An optimistic approximation would label about 20% of the cohort of a typical diploma program as industry-worthy.

If I could fail the other 80% and save future employers needless pain and frustration, I would. Luckily for them (the students, not the employers), I was told I cannot. The almighty bell-curve has to be respected. So what happens? Curriculum gets watered down, so that these students can “pass”. Life becomes easier. 3D graphics too hard? Let’s just stick to 2D, shall we? Maybe you don’t really have to learn A* when a turn-left algorithm will do? The end result is  a lot of complaints from students and industry alike that the courses are not providing enough foundation. *sigh*

If you are a student and wondering why it’s so damn hard to get into say – Digipen, this is the reason why. They are weeding out the 80% who really have no place in a games development course. Harsh, but you have to respect them for it. At least they have standards.

Course Management

We already know the curriculum woes that result from a weak student body. There are also other pressures, like pressure from industry. These well-meaning institutions decide to take the sensible approach and go out to ask game development companies what they need. What do they get in response? Everything under the sky! We need Unity3D, C++, C#, Java, Flash, Objective C, Torque (RIP), console devkits, UDK, etc. Every company has different requirements, all of which evolve mutate with time, and given that most course managers don’t have a grounding in the game development process, what are they to do? Who are they to turn to? Hell if I know.

The Employer

I have helped a few of my clients to interview potential employees in the past. Bear in mind that these are all SMC’s (small-medium companies), so it might not apply to the big boys. Recruiting in Singapore is hard. Why is it hard? Because there is nobody out there! You can put out an ad in the papers or any number of job recruitment sites. What do you end up with? A ton of resumes from generic people who have no game industry experience, no game-related academic qualifications, and likely don’t even play games themselves. This is even so if you highlight and boldface these as requirements. Oh, and you also get a healthy number of applications from India and China.

So after you weed through the mountain of resumes and find the handful of people who might have some inkling about what the job is about, you call them in for an interview. There are many points of failure in this process. The first hurdle is confidence. We get interviewees that are so nervous and/or quiet that we feel sorry for them. Do we hire them because we feel pity? No.

Then there’s the portfolio. There is no excuse not to have a portfolio. If you are a programmer, write some code. If you are an artist, draw something. We don’t really care if you have a degree or a diploma with 3.8 GPA. We want to see what you have done and how you think. That is all that matters. If you don’t have it, you don’t matter.

After that, there’s the test. I designed a practical programming test for one of my previous clients. I thought it was fairly straight forward – programming 2D behavior with the rendering, input and general framework already written for them. Sadly, very few even got past the first step of the test, which was to call a function which I wrote for them, in response to an input event. Do I really want to hire anybody who can’t even figure that out in an hour?

I recently went through the experience from the other side. A potential employer (quite a large company) gave me a written test. It was basically on optimization (by optimization we mean bitwise operators), C++ and OpenGL. It was a two and a half hour test, and was fairly challenging. I shudder to think of the applicants who went through my test sitting for this one. Maybe most people don’t make it through this test? Apparently so. I have an interview on Tuesday.

While the employee market is sparse, the intern market seems to be thriving. Almost everywhere I go, I run into interns. Oftentimes, they are my former students. You would think that it would be a simple matter to hire interns, train them up, and hire them as full time employees when they graduate. Not so easy! There’s this thing called the Army which sucks up all these interns right after they graduate and holds them in stasis for two years, possibly with brain decay. It turns out that females are immune to this monstrosity, but they are so rare in this line of work. So if you are a game developer of the fairer sex, know that everybody loves you, and not just for your stunning good looks.

Job Seekers

I entered the job market with two objectives in mind. First, I want to move overseas. Second, I want to move into game design. Any job that fulfills either criteria and opens the possibility of later expansion into the other, I will happily entertain. With that plan in mind, I jumped.

The Game Design Path

There are precious few companies in Singapore that are hiring game designers AND have some sort of way to get me deployed overseas in the future. Most of these are the bigger boys. Out of these large wealthy companies, I only fancied a couple. This is largely because I went for interviews with a lot of these companies in the past and the culture did not appeal. Why did I go for these interviews, you might ask? Headhunters called, and as long as somebody calls, I’m always happy to talk and gather intelligence. Well, out of the two that I kind of liked, neither were hiring designers. I sent my resume in anyway, and received no response. They are probably snickering away at this crazy programmer who thinks he’s a designer.

The only other company I approached was one whose culture would allow me to travel. The nice people there did respond, and helpfully suggested I look for Tech Director positions or something more befitting my experience. After I explained the whole game design spiel, they probably felt I smell too funny to hire. What they did tell me is that they felt I would probably find myself dissatisfied with entry-level game designer salary as compared to what I can draw freelance, and end up leaving. I have to admit that it’s a very good rational reason, given that I’m Singaporean, and all Singaporeans love their $$$.

The Overseas Path

I discovered that there are international recruiting agencies that cater specifically to the game industry. That certainly wasn’t there the last time I went job hunting. So I signed myself up and a nice British bloke called me after a day or two to clarify some details and lay some expectations. “Very professional!” I thought, much impressed. I never heard from him again, ever.

After similar experiences from a couple others, I can unscientifically conclude that recruitment agencies do not work. Well, not in this way anyway. The only recruiters that have managed to get me job interviews fall into two categories. The first is the kind that come and look for you (i.e. the headhunters). The second are those that have a vacancies that they are looking to fill and post ads everywhere.

Recruiters aside, where do I find job vacancies? Typically they are places like the Gamasutra job section, the game development group in Linkedin, personal referrals (God bless their souls), etc. One thing about these vacancies is that most of them are looking for people specifically in the States, or specifically in Europe. Why? Because immigration is hard. There’s a limit on the number of green cards issued, so overseas labor is unnecessarily complex to hire, not to mention the risk. In many cases, especially the smaller companies (which I love so much), I offered to offset some of that risk by relocating at my own expense. Gotta give some to get some!

This is not the end of my master plan. After my current project is wrapped up, if I still haven’t found a job that I like (never settle for a job you don’t like), I will travel myself to these Mecca’s of game development and see what I can find on the ground. This is the correct way to do it, or so I’ve found out. You can’t simply send out your resume and expect to land something worthwhile. Until I have freedom to fly, I’ll test that theory and get back to you if I disprove it. Not like I have anything to lose.


This is so easy to do that I am wondering why there are not more people doing it. Everybody wants to go “indie” and set up their own company, or they want to enroll in the rat race and be a cog in some big corporation. Freelancing provides a great lifestyle, pays pretty well, and supposedly gives you no sense of security whatsoever. So why on earth would I want to move away from it? I’m bored, and I want change. Me and stability don’t see eye to eye. Me and challenge – best buddies!

So if you want to be a successful freelancer, what should you do? The first step is to find a full-time job. “What?!” I hear you cry. Freelancing is easy but it’s not thaaat easy. First you have to have the skill. You also need some sort of credible portfolio that includes published works. The place to get both is in a full-time job. Having had the fortune of starting out when the game industry in Singapore just came out of the womb, my first full-time job was a nearly unpaid full-time job. I simply treated it as school, without the school fees. Self-rationalization is a skill.

The next thing is hooking up with clients. How do you do this? Networking. What is networking? It’s basically talking to everybody and anybody you meet. Go to IGDA chapter meetings, drinking sessions, networking sessions, product launches. Dish your namecard around, let everybody know what you are doing but don’t solicit business unless a “mutually-beneficial opportunity” happens to surface. Just get to know people, preferably personally as well as professionally. Chances are, nobody will throw themselves at your feet begging for you to work for them. But wait two to five years, and suddenly you get this call or referral, and you know your efforts have paid off.

You will also need a website, like this one. From this website, you can see a good sample of the projects I’ve done in the past, learn more about what I do, and even what sort of person I am. To top it off, I have all sorts of useful essays on things that help in game development such as this, the article you are reading now. Do your search engine optimization and make sure you can get Googled. Link it to Facebook, LinkedIn, and whatever other social networking thing you have. Be active and keep it current but do not spam useless stuff. You have no idea how many people have contacted me simply because of this website. Sure, some of them are weirdos, but most have some form of legitimate business to conduct.

Now that you have the clients, you have to manage them. The secret to freelancing successfully is to always have 2-3 projects ongoing at any one time. If you desire some measure of stability, one of those projects can be teaching at an educational institution. Why multiple projects? If you have been doing your homework and developed your skill, you should now be able to work many times faster than the average grunt. A lot of the time, however, will be spent waiting. Waiting for art, waiting for approval, waiting for design decisions, etc. So while you are waiting, why not do another project? If I work full-tilt, 3 projects are not a problem, and I don’t even have to work weekends (most of the time). Sometimes (like now), I drop down to one, just to have breather and smell the roses. Quality of life vs quantity of money – you decide.

Now the biggest secret behind freelance success? There are no other freelance game programmers in Singapore! There used to be a couple of others around, so we could chuck excess work back and forth, but the others have since found other pursuits and now I am exiting as well. OMG!!! Can you say power vacuum?! That said, there are companies that offer contract services, but people often reason that freelancers will be cheaper than hiring these companies. Partially true. We don’t have overheads. Office rental is – $10 a day for a venti vanilla latte plus a snack at Starbucks. Don’t have to pay snooty employees. Nothing!

At the same time though, don’t undercharge. A student once asked me how much I charge per project. I said it depends on the project and it’s a trade secret anyway. The real answer is that it depends on demand. If you are getting more jobs than you can handle, charge more because you are obviously too damn cheap for the value you provide! It has less to do with how much you think your time with worth than how much they think your services are worth. I also like to charge per feature rather than per hour. This lets the client pull things in and out of the project as it progresses, as they are wont to do anyway, and you get to quote them on every single change. I also charge less for games that I think will be particularly portfolio friendly (here’s looking at you, giant robot with guns game – you heartbreaker!), or that I simply find more fun to work on. My business, my rates!

The Meaning of Life

Posted: March 6th, 2011 | Author: | Filed under: Soapbox | 3 Comments »

Where do I begin? I am not a religious person. While I do not believe in God(s) per se, I do not deny that there could well be something out there. I also recognize that it is beyond my ability to determine what is what in the great beyond, so I choose to simply put that question to the side. Perhaps one day, when I recline comfortably in my grave, I will be able to shine some light on that issue. Today is not that day, or so I hope.

So what do I believe in? Some people believe that they are put on this Earth for a purpose. More power to them because it makes life or any other endeavour so much easier when there is at least a vague direction to follow. I do not entertain such a luxury. I believe that it is up to me to find my own way, purposeful or not, and live through life with no regrets but my own. I refuse to live at another’s whim, and would not expect another to live at mine. True, I do owe a great deal to a lot of people – family, friends and other people in my life. However, as much as I am indebted to them, I claim this life for my own and reserve messing it up as my own privilege.

I began my working life in a small company called Coaster Computer Services. My boss, Victor, was a shrewd small-time businessman who had me creating software solutions for other small businesses. He is also the man who had the ability (which he often exercised) to use the word “fuck” in the most gentle, non-vulgar and non-offensive way possible. I learnt a lot under his wing including how to deal with clients and how to develop software from design to delivery and beyond. As pleasant as working there was, I had far more ambition (in other words, I wanted more money, more fame and more glamour) than that job could offer and through a series of events moved on to the next phase in my career.

From a small-time software house, I spread my wings and starting working on multi-million dollar projects as an employee of IBM. I was part of the business consulting group, working in a large team spanning four continents creating and deploying backends for the largest banks in the world. I was part of the working class, with my formal (by today’s standards) shirt and pants, walking down the street to work with millions of other people just like me. The hours were gruelling, with team members turning up for work at the office at practically any time of the day or night. I was having the time of my life.

The group I was in worked under the absolute best project manager I’ve ever had the pleasure to work for to this day. His name was David, a former techie turned manager turned director. He was our guardian angel, protecting us from office politics, enforcing food and rest when we overstretched our limits and basically steamrolling through anything that got in the way of us doing our jobs. He is well-respected, probably filthy rich and obviously enjoyed his job. One day, I had a good look at him, where he was in life and the lifestyle he was living. Was this the role-model I could aspire to emulate ten or twenty years down the road? I looked deep into myself and realize that the answer was no.

It is at this point that I really started to understand myself, life and the world in general. Money, I realized, was only a means to an end. What is that end? Personal satisfaction. Many people go through their lives slogging through work mindlessly so that they may raise enough money to “buy” happiness in the form of material creature comforts and a better quality of life. While I am all in support of material luxuries (yes, I’m no Gandhi), what disagreed with me was the slogging part. Why spend a majority of your life doing an activity that you do not enjoy just for the sake of being happy during whatever time is left over? I decided to cut to the chase. I’d be happy first and worry about the money later.

I was always fascinated by video games, both playing as well as creating them. (though admittedly mostly playing them) In my university days, I had three main priorities. My top priority was… competitive Scrabble. Yes, I am and have always been nerd, thank you! We had a great team that trained hard together. The camaraderie was so great that I felt I was a significant part of a bigger whole. We played, we conquered, we celebrated. My second priority was the Leviathan. The Leviathan is an online text-based roleplaying game. Think of World of Warcraft but without the graphics. While I played that for a while, I soon went into development, becoming a Wizard (i.e. a coder) and created new areas and mechanics for the players. It was set up so that the development environment was part of the live environment. It is a coder’s paradise with the instant gratification of player comments and complaints as they explore your new creations and their moans of anguish when you inadvertently crash the whole game. My third priority was scraping through on studies so that I actually got my degree. I hardly attended any lectures or tutorials but studied on my own as well as in a study group. I admit this was mostly done so that I could devote more time to my first two priorities.

Alright, back to the career bit. During my days in IBM, I did somehow manage to eke out some personal R&R time. I played my first ever MMO which was Dark Age of Camelot. In this game, I had the pleasure of making the acquaintence of a fine fellow called Alvin. Alvin himself, was in the fledgling game industry in Singapore. He set up his own company, Nexgen Studio, and just simply went for it. With a mish-mash of interns and recent graduates, he managed to produce an FPS demo. It sucked (sorry Alvin!), but it was a good start for a business still in its infancy. Like all other fresh-faced developers with delusions of grandeur, he wanted to create an MMORPG. (admit it, everybody goes through that stage) He had a business plan, a design, and even a comprehensive background story. He showed me what he had, and I promptly quit my job and turned up at his doorstep to work for next to nothing (not that he could afford to pay anybody at that point). He expressed amazement at encountering somebody as insane as he was.

We worked hard for the next year and a half. Though the going was tough, it was also a lot of fun. I got free reign to do just about anything ranging from project management to marketing to meeting VC’s to programming. It was a blast. I gave the company a year to make or bust. Much to my chagrin, neither happened. Instead, we merely survived – somehow managing to subsist without going anywhere. It was a hard thing to do, but I informed Alvin that I was leaving the company. By then, we were good friends, almost brothers-in-arms. As I mentioned at the begining of this whole tirade, I live this life for nobody, good friend or no. So we parted ways and I went into the glorious world of freelancing. I am happy to say that after I departed, the company has done quite well for itself – a happy ending afterall.

Why did I become a freelancer? The honest truth is that I wanted to set up a company of my own but was too chickenshit. Instead, I would do the market research and find out how other companies operate from the inside, examine their challenges and mistakes, and learn from them while they footed the bill. Yes, I do not deny that I am an evil genius. You would think that making a living as a freelancer is difficult. In truth, it is disgustingly easy. All you need is the will to work hard and some semblence of discipline to maintain professionalism. You do your networking; shameless self-promotion. You make sure you do a good job and that your clients are satisfied, and word will spread. Business will flourish.

The lifestyle is great. I spend my days coding or meeting interesting people. I am seldom confined to an office for more than a couple days a week. I can truthfully claim to do game development in various branches of Starbucks Coffee and Burger King around the island. If I need a breather, I can simply take on less jobs. So it seems I have attained game developer nirvana. That is a bad thing.

If there is something that I have learnt about myself, it is that I dislike being comfortable. The freelancing job fits me quite well because I can flit from place to place, project to project, and it is always different. I learn new technologies and techniques along the way and all is good in the world. However, lately, I have been finding it increasingly difficult to sit in front of the screen and do actual work. If I were the typical Singaporean, I would grit my teeth, force it through with sheer willpower and get the job done. Obviously, having just said that, I did exactly the opposite. I have been spending a fair amount of time in introspection (i.e. sitting around and doing nothing). There is a reason for my failing drive and that reason is not laziness. I have always been lazy and that has never gotten in the way before simply because I love my job too damn much. So what do I want out of life and why does it feel like my current direction is off-kilter?

I definitely still want to make games. The original plan was to set up a company so that I can make the games I want to make. After all, I have already learnt so many lessons from all my previous suc… clients. Why not put them to their intended use? Have I not suffered through all manner of brain-dead or ludicrous “designs” and “concepts” that I have earned the right to make something on my own? To be honest with myself, I don’t even care if it sells or is profitable. I am past caring too much about money other than the occasional need to eat. Yes, there is a flaw in the master plan that I failed to perceive when I set out on this whole venture. As Steve Jobs has said, this changes everything… again.

If I were to set up a company, I would be too embroiled in administration to be usefully engaged in the development process. Sure, I would have the privilege of being the boss and well… bossing people around. “Yes, you should do this. No, don’t do that. This is the way to do it… Where’s your company spirit? Worship me because I pay your salary!” The truth is, as has been blatantly demonstrated to me, management messing around with the development process too much is a bad thing. Bad for the project, bad for the team. I would never have the fine-grained control over the project that I cherish.

To add to that, I want to do other things as well. I would love to learn how to draw/paint, play beautiful music, engage in creative writing. I have no illusions of being “good” at any of them, but these are indulgences rather than core skills. I want to experience life to the fullest and take in all that it offers me and then some. I want to always keep moving and never stop till day I cannot move anymore. For all this, I would be willing to be the serf instead of the ruler. Who in their left mind would not?

With all that said and done, where do I go from here? I have decided on two long term objectives. First, I want to make the shift to game design. Second, I want to get out of Singapore and move to somewhere completely different. Make no mistake, Singapore is a great place. It has low crime, good infrastructure, excellent quality of life and is probably one of the easiest places to make money in. However, with 6 million people crammed on a little red dot, all chattering and yammering as they go through their lives like automatons… I need a change.

Ultimately, is that not what life is all about? I pride myself on following through on arbitrary decisions made after a period of daydreaming and being non-productive. You cannot chase dreams if you do not have any and one dream is as good any other, no?

I wandered lonely as a cloud

Posted: February 19th, 2011 | Author: | Filed under: Tutorials | No Comments »

I wandered lonely as a cloud
That floats on high o’er vales and hills,
When all at once I saw a crowd,
A host, of golden daffodils;
Beside the lake, beneath the trees,
Fluttering and dancing in the breeze.

Continuous as the stars that shine
And twinkle on the milky way,
They stretched in never-ending line
Along the margin of a bay:
Ten thousand saw I at a glance,
Tossing their heads in sprightly dance.

The waves beside them danced, but they
Out-did the sparkling leaves in glee;
A poet could not be but gay,
In such a jocund company!
I gazed—and gazed—but little thought
What wealth the show to me had brought:

For oft, when on my couch I lie
In vacant or in pensive mood,
They flash upon that inward eye
Which is the bliss of solitude;
And then my heart with pleasure fills,
And dances with the daffodils.

– Willam Wordsworth

Put it on the cloud!  The not-so-latest trend of web-hosting has finally caught up to me.  Today, however, we’re going to take a quick overview of Amazon’s Web Services (AWS) so that we can dream of the possibilities it may bring to our own development projects.  AWS is, in fact, quite well used by some of the larger casual game developers like Zynga to manage their large user base.

Amazon provides its services not as one, but rather several packages. This can be is daunting to a first-time user.  However, upon closer inspection, we don’t really need to know about all the nitty gritty details. Once you activate one service, all the other dependencies are automatically bundled in, saving you from the headache.

Computing Power

This is the primary service we are concerned about, Amazon Elastic Compute Cloud (EC2). Amazon has a large number of servers that can provide a tremendous amount of computing power. What EC2 does is create a virtual machine instance on this server farm, on which you can basically run whatever it is you want. You get billed on the amount of CPU time you consume. So the more intensive your tasks, the more you pay.

EC2 instances can easily be set up via a web-based control panel called the AWS Mangement Console.  There are a variety of different types of instances that you can create, depending on your expected computing load, ranging from micro to large. You can create as many instances as you want to, as long as you have the $$$ to back it up. Amazon provides a set of images that you can have pre-installed on the newly created instance. It boils down to a choice between Amazon’s version of Linux, Suse, and various flavors of Windows. I went with Amazon Linux, since that was free and I’m cheap.

When I created the instance, it was up within about 30 seconds, with a bare bones OS install.  It handily creates an ssh key-pair for you, so you can readily ssh into your new instance via Amazon’s public DNS server.  Adding packages was easy as you simply use yum. Unlike setting up your own Linux environment, installing packages is pretty fast since they are all hosted on the same server farm. I just installed gcc and did the obligatory “Hello World”. Yup, it works!

You can assign up to 5 elastic IPs to your instances. By elastic IPs, we mean public IPv4 addresses. These come free of charge, and will stay constant as long as your instance is up and running. However, if you have an elastic IP attached to a stopped instance for more than an hour, they start charging you for it. Kind of like how those buffet steamboat places used to charge you for whatever leftover food you have. It discourages waste. Amazon does not provide domain name services, so you will need an external provider if you want a fancy non-numeric URL.

Once you have server configured, you can in theory, save the configuration as an image or AMI. This allows you to then spawn multiple instances with the same configuration if load gets a bit high.

Data Storage

Your EC2 instances come with some space for you they call ephemeral storage. What that rather long word means is that once that instance is shut down, all the data on that instance is gone. The purpose of that storage is more for run-time operation rather than long term operation.

What you can do is use something called Elastic Block Store (yes, they really like the word “Elastic”) or EBS. This is simply storage space. Each EBS can be attached to your instance and mounted as a volume, providing you with persistent storage. What’s more, you can image your data and create multiple snapshots for use as backup, or for other instances to serve up data. Via Amazon’s Simple Storage Service (S3), this data can be transmitted between Amazon’s four data centers (2 in the US, 1 in Europe, 1 in Singapore).

Load Balancing

Amazon provides load balancing via… you guessed it – Elastic Load Balancing. Unfortunately for us game developers, it does not automagically load-balance your homebrew MMO. It is instead, more catered for web servers. So if you are writing a PHP-based MMO, more power to you! If not, you will have to architect your load-balancing mechanism by yourself. What this means is that your server code will need to be written atomically enough so that multiple instances of your code can be run concurrently on different virtual machines. In addition, you will need to write load balancing gateways that dole out incoming traffic to the free servers.

To aid you a bit, Amazon Cloudwatch provides you with data such as CPU and Memory consumption so that you can gauge when you need to spawn additional instances. 3rd party vendors like Rightscale provide additional paid services to enhance scalability by allowing you to rapidly spawn a large number of instances from pre-written scripts, even allowing dynamic resizing based on server load.


Amazon Web Services are indeed fairly easy to use. The scalability means that you can transit from a development environment to a deployed one with relative ease. Signing up was fairly hassle free. Just provide your credit card and telephone number and they will verify you. Given that the first 750 hours of compute time on a micro instance are given to you free of charge, there’s no reason not to sign up and play around with it yourself. However, once again as we oft do learn, it is no silver bullet. Making your game truly scalable still heavily rests on the shoulders of the developer. All Amazon does is provide the infrastructure.

The Big Red Button Game

Posted: February 15th, 2011 | Author: | Filed under: Projects | No Comments »
Big Red button

Big Red button

Alright, this isn’t really a full-fledged project so much as an experiment with technologies. I was contracted to construct a Facebook game The tool of choice was Unity3D, and it was to be a web-based game. As with all public-facing projects, it always pays to know exactly what happens when you hit that publish button and release it to the wolves. Hence, I created this nonsense game and launched it, just to see what would happen.

As for what it is, there’s a big red button on the screen. When you press it, you win the game. I’m sure I can make up some philosophical BS  about it given enough time. It has a high score table, and is integrated with Facebook, using the API to grab both the user details, as well as post personal best high scores to their wall.

Unity 3D

Unity was chosen because the proposed ‘other’ game was to comprise of both 2D and 3D components. It was uncertain if it would later extend to other platforms. Also, the development period was rather short, encouraging the use of rapid development tools.

From my previous rants on Unity, you can probably tell I am not a big fan.  I would probably still recommend it for project teams that are artist heavy and programmer light, but generally demur from using it myself.  However, this time I bit the bullet and gave it a go.

Developing a web app is easy. Just set a target in the build settings and say what size you want the window to be and voila! Automagic! In fact, most things are like that. The UI system was pretty ugly, but I spent some of the project budget on SpriteManager 2 and EZGui which significantly increased the automagicalness.  All the dragging and dropping somewhat irked me and made me feel unclean, but that’s just me. In truth, it was quite easy to use.

The editors, UniSciTE on Windows and Unitron on Mac, were considerably underwhelming. I ended up going back to my full-screen Vim which I love so much. However, every now and then, I’d accidentally double-click a script and the editor would jump out in my face as if it were Halloween. An integrated text editor would do wonders for a product like this.

Communication between the Unity web-app and its home web page scripts was fairly straightforward. Communication and fetching other web resources via PHP scripts was equally  easy. The unfortunate thing is that a built-in security “feature” prevents you from loading pages that are not in your domain. Which means that if my PHP scripts are on my web server, I can’t access them from a local build but have to either upload the build to server or install PHP and Apache and whatever else on my local machine, which is decidedly not cool.

One other thing is that the Mac build of Unity is significantly less polished and clunkier than the Windows build. Importing of assets takes longer. Certain windows seem to lose their graphical context until you grab the window and drag it around the screen. Also there are slight differences in workflow. (e.g. You can’t name the webplayer object when you build it under Mac Unity, but you can under Windows) It’s almost as if Unity has two teams. They put the ‘A’ team on the Windows build and the ‘B’ team on the Mac build, gave them the same specifications and let them develop independently.

Facebook API

The Facebook API has changed considerably since I last used it scarcely more than a year ago. You no longer have to put weird strings in the Application settings. Instead you can access all the functionality through their Graph API. Feed your query to the specified URL and things just happen! It also comes with JSON support, if that is your thing.

However, I had to give up on quite a bit of scripting because the Unity web player appears to render on top of everything, no matter what fancy CSS tricks you play. In the end, simplicity wins.

The tools that Facebook provides includes statistical information (they call it ‘Insights’) which gives you a rough idea of how many people are playing the game,  the number ‘likes’ you are getting, and the volume of comments.

One unfortunate thing is that there are actually 2 pages for each Facebook app. One is the actual application page where you can play the game. The other is some sort of fan page for posting comments, news updates and the like. A big mistake I made was promoting the fan page rather than the actual app page.


Unity is certainly a viable platform for developing Facebook games. Facebook and server integration are relatively simple, and there is a high degree of automation. Webplayer installation is seamless for the most part. SpriteManager 2 and EZGui are must-haves for any sort of 2D or UI work. If your programming team is small and in numbers not very experienced in general development, this is the ideal engine to use.

The final ‘game’ can be found here.

Nerding Out The Windows Console

Posted: February 3rd, 2011 | Author: | Filed under: Tutorials | No Comments »
PuttyCyg to the Rescue!

PuttyCyg to the Rescue!

So you bought a Mac, and oohed and ahhed at the graphics and the user interface (or maybe you hated it, I don’t really care).  Then the inner nerd called to you and you started messing around with the terminal, loving the linux-like console and enjoying the power that a real OS command line gives you. Maybe you even went so far as to customize the look of your console, perhaps installing Visor in the process for a beautiful full-screen terminal. Ahh, how we love our text.

Then you turn back to your Windows 7 machine and oh how loathsome it is to work with now! MS Dos Prompt just does not measure up. Even their new-fangled PowerShell does not satisfy. We could perhaps forgive this if we could at least get it to run in full screen. But woe is you as  you realize they took out that full-screen mode feature when they moved from Windows XP to Windows Vista. So what’s a poor nerd to do?

Well, if you are a true nerd, you’ve probably heard of Cygwin. Back in the day, it was a way to run a linux distro on a virtual machine within Windows itself. Comes with X11 and all those fancy goodies. Well apparently, they had a change in philosophy when I wasn’t looking and it now comes with a minimal install. You have to choose the packages that go into your build, making it leaner and meaner from the get-go. So yes, go forth and download that. Additional packages to install would be inetutils (which gives you ftp and and stuff like that), as well as ssh (why Windows doesn’t have this natively is beyond me). If it so tickles you, you can get good stuff like gcc and automake as well. And of course, we can never forget good old Vim. If you’re an Emacs fan, that’s available too.  And if you are not quite so nerdy, there’s always stuff like Nano.

So you installed Cygwin and got it running and…UGHGHHH!!! You’re still stuck with that same lousy non-fullscreenable command prompt, albeit with Unixy power. Well, not to worry. Go and get a special version of Putty (this is the program that windows people use to overcome their ssh deficiency) called PuttyCyg.  This will allow you to start up a session in… you guessed it, your own Cygwin instance! Also, unlike the command prompt, you can maximize, or even full-screen it! Amazing!

An interesting side-effect is that since we installed the ssh package, we can ssh directly from our command window, thus voiding the original functionality of Putty. An irony that all true nerds can appreciate. To streamline the whole process, you can alter the windows shortcut to Putty, and feed in a command-line parameter to get it to start up your Cygwin session on the click of a button!

All this seems like an overkill if you consider my original intention. All I wanted was a full-screen Vim. Sure, there’s gVim, but it sucks in the full-screen department as depending on your font size, it’s not quite full screen. It also comes with fancy schmancy mouse and gui stuff that makes it quite… unVimlike.  So yes, I brought out the sledgehammer to squish the itty-bitty ant, and yay! It’s dead! Mission accomplished.

Taking Music Seriously

Posted: January 26th, 2011 | Author: | Filed under: Soapbox | No Comments »


Just the other day, the original Die Hard was shown on TV… and it was good!  There was one little niggle that bothered me though. During the action scenes, these weird orchestral swells would play in the background, supposedly to build up tension.  I supposed back in the 80’s, that was the norm and we never gave it a second thought.  Today, however, it just seems so out of place.

So I went through my video library and looked at two films that I really liked for their style and soundtrack… Requiem for a Dream and Lola Rentt.  In each of these, the movements on screen, be they full screen transitions or simple movements were carefully choreographed with the music. The music itself complemented the atmosphere in each of those films – dark and foreboding in the case of Requiem, speedy and action-packed for Lola.  There was a phrase to describe this sort of cinematography. It took a little while to wrack my brains before I got my “Ah hah!”… MTV style.

So for more inspiration, I flipped over to the MTV channel which I haven’t watched for years… decades even. And lo behold! MTV is no longer like that. All it seems to be now is music playing with general “stuff” happening on screen. There’s no oomph to it like I remembered from the 90’s. Youtube to the rescue… I found curiously enough that the Korean music videos actually do feature this style, as well as a lot of imagination put into it. Videos from SNSD, Wonder Girls, JYP… all had that cutting edge and were enthralling (and not just because of my inner perv). I also realize that this was something I was pretty conscious of in the making of my Oversight video, even without formal video editing training.

So how do we bring this over to game development? Other than rhythm games, we seldom see music tightly linked with the action on screen. This is partly because it is really hard to predict the player inputs. But it is also largely because we, as game developers, tend to treat it as an afterthought. Yeah, with my huge army horde marching in, I know I should play something majestic to add atmosphere. But do I ever go so far as to have them marching in step with the music? Not really.

Part of the reason why we don’t really think that way is because of the tools we use. Traditionally, we at most tie the playing of music pieces to certain events. We don’t have tools that, for example, generate an event with every bass beat in the music score.  Why? Because nobody ever thinks that way. We are stuck in a rut.

When I get around to the audio portion of Darwena, I would like to incorporate these ideas, and see if they have an impact on the type of games that get produced from it. Would it even go so far as to produce a signature style? “That must be a Darwena game because it has that rhythmic feel!” That’ll be cool to hear.

Programming, How To

Posted: January 11th, 2011 | Author: | Filed under: Tutorials | 5 Comments »
Problems in Programming

Problems in Programming

Good programmers, especially game programmers have this mystique about them.  They seem to be able to juggle ginormous amounts of machine gibberish and cobble it into an application or game that does all sorts of wonderful things, almost as if it has a life of its own. People think that they must be really really smart, and for the most part, they let them think that. Hey, if you can’t be handsome or muscular, at least you can be clever, right?

What they told us

Most courses introduce programming as a set of instructions that the machine follows. “Look, the computer looks for this keyword called ‘main’, then it does whatever you put in between the brackets.” And thus they are introduced to the wonder that is… “Hello World!” Hey look! you can make a couple of words appear on screen, therefore you are making progress! Wonderful! After that, they are introduced to constructs like branches and loops, maybe even functions and classes. The programs the student writes becomes more complex until they get stuck.

“Yeah, I get how these programming constructs work, but how do I put them together to make the program do what I want?” At this stage, they get taught UML. Yeah, this is what we call software engineering, where we plan out how the program will work by drawing pretty pictures! This gives rise to two new problems. First, how the hell do you know if your pretty picture is correct, given that you could draw it any number of ways and still be a somewhat decent representation? And after that, how do you translate it into actual usable code?

This is when they get introduced to design patterns. Hey look! These are like standard answers thought up by some four very smart people? How do we know there are only four people? They are called the Gang of Four, duh! Come see their voluminous tome of knowledge! For each problem that you are trying to solve, find the pattern that fits and plug it in. Hey presto! We end up with a group of programmers who think that programming is really really hard, cobbling programs together out of disparate pieces of other peoples’ code and tweaking the variables, hoping that everything will magically come together.

Take a deep breath…

and forget all that for now. Let’s go back to the basics. What is a programming language? This is the medium through which you direct the computer to do what you want. Plain and simple. It comprises of two parts, the “Programming” and the “Language”. Let’s go through the easiest part first.


Language is exactly what it sounds like. It’s just a different way of speaking/writing. It still does the same thing, which is conveying information from one party to another. There is no difference between a programming language and a normal language like Japanese or English, except that it is much much easier to learn. Why is it easier to learn? The vocabulary many times smaller than a traditional language. For example, if you want to understand C, all you need to understand are less than a hundred words. Compare that to the 171,476 (as listed in Oxford) words in common use for the English language.

If you want to learn Java, all you have to figure out is what words correspond to what you are used to using in C, and voila, you are a Java programmer! In fact the only time you find real major differences is when they don’t support certain features. These however are easy to categorise.

  1. Is it a generic programming language? That means you can use all the good stuff like templates to get around data types. (e.g. C++, Java)
  2. Is it an object-oriented programming language? That means you can use classes and objects. (e.g. Python)
  3. Is it a procedural language? That means you can use functions. (e.g. C)
  4. If it is none of the above, you are probably coding in assembly and have to conceptualize all those nice features by your onesome.

Whatever the case, the art of using a language is merely translating from your native tongue (which I presume is English since you are reading this), into the programming language of your choice. What’s that stuff that was in your native tongue that you have to translate? Why, that is the instructions you wanted to give the computer to tell it what to do, and this stems from the next big part… the “Programming” part.


Now that you know how to express yourself properly, you now need to tell the computer how to do stuff. Unfortunately, in spite of decades of technological progress that boasts of multi-core processors and terabytes of memory, computers are still as dumb as a brick. You need to explicitly tell them what to do each and every single step of the way. Unfortunately, due to our poor conditioning thanks to our exposure to ambiguous languages like English, most people struggle in drilling down to the absolute steps that are necessary to accomplish the task. It is, however, not a complicated process.

It starts of with a problem. (If you didn’t have a problem to solve, why are you writing a program? For fun? Blasphemy!). You take this problem, and you break it down into the steps you need to solve it. Each step then in itself, poses a problem. So you take all of those, and break those down, until the instructions become atomic enough for the computer to execute. That sounds a bit abstract so lets make an analogy.

Assume that you are on the couch, watching TV, when you get the overwhelming urge for a beer. So there you have a problem, need a beer. Let’s further assume that you, as the thinking programmer, are the brain, and you have instruct the stupid non-thinking computer, which is the body. So being so smart, you say, “Go to the kitchen, get the beer from the fridge and drink it.”. The body goes, “Go?” So you have to clarify, “Get up, turn right, walk two steps, turn right again, walk five steps, then turn left.” To which the body haughtily replies, “Get up?” So you have to go, “Flex both quadriceps, while pushing arms forward to maintain balance, until fully extended and upright.” Maybe this is something the body is finally capable of doing, so hurrah! Now you can go through the process of instructing it how to walk…

If you are lucky, some guy in the past might have already figured out that walking is a good ability to have. So he compiled as set of instructions on how to walk, which you can then feed to the body, merely having to tell it where to walk to. Well, isn’t that easier! These pre-made instruction packs, commonly called APIs or SDKs save you from having to laboriously go through each and every minute detail. However, before you use these instruction packs, buyer beware! The walk might not be perfect… it might have a limp! Or it might be only good for the first ten steps. Or it might leave you prone to falling down on certain terrain. Always read the fine print and test it to make sure it does what you think it is doing and be aware of any side effects.

So now you have the gist of how to program, you might find yourself encountering a couple of problems. The first is that you can’t figure out how to properly break down a problem or part of a problem. The second, particularly for game programmers, is that your set of instructions is so long and convoluted that the machine simply can’t execute it fast enough. Regardless of which, programmers tend to apply the same solution… “Think harder!”.  So you end up with these zombie programmers staring mindlessly at the screen, wracking their brains at the problem till their heads hurt and they slowly lose their minds.

The secret that eludes these programmers is that it isn’t matter of finding a solution. It is instead perceiving the problem. That’s right, it’s a matter of perception! Oh yes I see you, the artist giggling in the corner about our silly programmer post. Indeed, the artists have known these for years. Before an artist learns to draw, he is first taught to see. Once he can perceive the objects in our world in the correct way, he can apply it to canvas. Similarly, depending on how you perceive the problem, different solutions will become apparent. How do you change your perception? You have to identify and challenge your presuppositions. Tear down the things that you always take for granted and ask what if? Ask yourself what the problem is really about, and what else can it be about instead? The first few times, this can be really hard, but as you go on, it gets easier because *gasp* you are becoming a rational creature! And that is really difficult for a human being.

Good programmers take this concept and push it even further. Even when they are not stuck, they will view the problem from several different angles, and pick the best and simplest solutions that present themselves. That is why it seems that their code is always ten times shorter than yours, simpler, and faster to execute. The more angles they cover, the better pick they will have, and the less code they will eventually have to write. This is why when writing code, 90% of your time should be spent thinking about the solution, and 10% of the time typing it out in code. (Yeah, I pulled those numbers out of my ass, but you get the idea)

So back to our beer analogy, challenge your suppositions. Do we necessarily have to go over to the beer? Can we make the beer somehow come to us instead? Thus we fire up our trusty speech API and yell the magic words, “Bitch! Get me a beer!”. Wait ten seconds (during which you can do other stuff), and a freshly opened beer appears magically in your hand. That, my friends, is what we call elegant programming!