Game Design, Programming and running a one-man games business…

Reducing OverDraw

When you make 2D, rather than 3D games, the two things that can slow your game down on older video cards (forgetting CPU limitations for now) are State Changes and Overdraw. State Changes are basically texture changes (drawing a different image). Doing this too often can really slow down older cards. Overdraw is the problem I was looking at yesterday on Kudos 2.

Kudos 2 is fixed at 1024 by 768 res. thats roughly 768,000 pixels, in 32 bit color, or just over 3MB to draw the whole screen. Because of the way video cards work, you have a front buffer, a backbuffer and the source art itself, so this equates to around 9MB in practice. Given that even the most wonky video cards have 32MB of RAM, this is no big deal, but this is assuming you just load up a 1024 x 768 texture and copy it to the screen.

The first problem is you can’t have a 1024 by 768 texture. DirectX prefers things to be ‘power of 2’ in each dimension, so you have to have 1024 by 1024, and as a worst case, waste a lot of space anyway. That’s only a minor problem though. The real problem is what happens if we end up drawing the same pixel too many times a frame. This is called overdraw, and its quite easy to let it slow down your game.

The best way to see how bad overdraw can be is to code a version of the game that draws every image as a fairly transparent white box. See below:

That’s kudos 2, AFTER I optimised some of it. The lighter the colour, the more times that same pixel is being redrawn. Sometimes, this is legit, because I am blending two images together, so you can’t just draw the top pixel, but in the majority of cases, it’s just inefficient. You can tell that one of the worst areas of overdraw (apart from the avatar, which is pretty inevitable) is the dialog boxes. These are a pain.

My dialog boxes are drawn on top of an existing background, theoretically giving me the opportunity to ‘punch a hole’ in the background and save some rendering. The dialog itself then has a ‘client area’ drawn using an additional image, which wastes space behind it. Any buttons on the dialog then add a third level of overdraw, and of course the text, or button icons are a fourth layer on top of that. If a tooltip pops up, we are at level five, and six for the tooltip text, seven if the cursor is above that! :D.

For video cards like mine, with an insane ‘fill-rate‘, it’s pretty irrelevant (The game runs at around 200 FPS right now), but I’m determined to make Kudos 2 easily usable on a low spec laptop with an Intel video card. I don’t lose *that* many sales due to poor performance with my existing games, but I’ve never made a game that looks casual enough for many owners of low spec PC’s to play before.

A Short History Of Positech

Ok, as it’s sort of a new blog, lets start with an introduction explaining how the hell I got to be doing this…

I first started coding in 1981 at age 11 on a Sinclair ZX81 with 1k of RAM. There was a long break after that when I went to university (LSE : Economics) and tried to become a rock star, then gave up and decided to work with computers. I had no degree in CS or programming experience so had to get an IT job instead (that’s how I ended up working in the city with trading software). I did that for 5 years, and while I was there, I started writing games and selling them online through my IT services company name (That’s why Positech is such a dire name, it’s an off-the-shelf company name). After a while, I tried to do it fulltime (around starship tycoon time) but failed to make enough money and desperately needed a job.
Because I had written about 5 finished games by then (various genres, and a bit amateurish), it was very easy to get interviews at games companies. I worked at Kuju for one day before realising it was NOT for me, and eventually took a job at Elixir Studios, where I did some brief work on Republic (yes! the infinite poly engine!), but mostly on an xbox launch title which we worked on for a year before they canned it. Bah.

From there, I had a brief stint at home again (wrote planetary defence) and then got a job at Lionhead. I was the AI guy (as well as various other stuff, save/load, optimising, copy-protection, GUI stuff etc). To anyone still at Lionhead reading this, the donuts was my idea. I apologise. Also, that cheap toaster is mine, be kind to it. I worked for 3 years on ‘The Movies’, but left just before it shipped. Ever since then I have been working for myself at home full-time. In the last year, I actually finally got around to converting a bedroom into an office so it seems much more professional now.

Some people who read the blog know me from the indie development scene, where I’ve been hanging around for a very long time. Some are people who enjoy my games, and do a fair bit of modding to them (I love making games moddable). And some are people who have read articles by me on the web, or ranted with or against me in various forums. Some might remember me as ‘the helpful one’ on the Lionhead forums, where I was often told off for talking openly about the game. It’s so cool to be able to say anything I want about the games I’m designing, even to post source code when it helps people.

I’ve worked for two people who are very good at game design and very good at PR. Hopefully, some of it rubbed off.

Anyway, that’s who the hell I am. Welcome!

Welcome to the new blog!

I finally got around to installing word press on the Positech Website so I no longer have my blog hosted elsewhere. Hurrah! Hopefully this is the start of me taking the blog a lot more seriously and putting up some more interesting stuff. The old blog ran for a looong time over at blogger, but it’s time to leave the old blog behind.

Hopefully I’ve installed things right and I won’t lose any readers from the old blog.