2025
June
GJK 27 Jun 2025
A long (long) time ago I made two big posts going through the GJK algorithm, how it works, and how to implement it efficiently. They were pretty cool and even had interactive diagrams in them designed to illustrate the geometric concepts and help to intuitively communicate why things work the way they do.
Read more...2014
August
Update: Getting Started with OpenSL on Android 23 Aug 2014
A while ago I made a post about the use of OpenSL on Android. That post has an error, outlined below:
Read more...2013
September
WebGL Index Validation 20 Sep 2013
If you've ever browsed through the WebGL spec, you've likely seen section 6: Differences Between WebGL and OpenGL ES 2.0. Right at the top of that section, we find section 6.1: Buffer Object Binding. That section reads as follows:
Read more...Introducing HenchLua 04 Sep 2013
This is the first of a series of posts on the subject of HenchLua. HenchLua is an implementation of the Lua VM in C#. It's targeted at projects running in otherwise limited .NET contexts, such as web-based Unity games (the Unity plugin, I believe, requires pure verifiable CIL), mobile apps (which are memory-limited and must meet the limitations of Mono's full AOT compiler, or apps that run on the .NET Compact Framework (whose garbage collector has some serious performance issues, as anyone who's written an XNA game targeted at the Xbox can attest).
Read more...2012
October
Bicubic Filtering in Fewer Taps 24 Oct 2012
This post is based on the technique described in GPU Gems 2, chapter 20, Fast Third-Order Texture Filtering. While that's certainly a good read, I found that the authors skipped over a lot of detail and optimized a little prematurely, making the result rather difficult to parse. If you've read and understood their paper, then this isn't going to be news to you.
Read more...September
Simple Flip Book Animation in WPF 13 Sep 2012
WPF makes it easy to animate numbers, colors, sizes, and a host of other properties. Unfortunately, it isn't easy to animate an ImageSource
property, which is what we're usually looking for when implementing a flip book animation. The closest we get out of the box is ObjectAnimationUsingKeyFrames, which works, but it's very tedious to set up all of the individual key frame times.
August
Using Win32 Icons in WPF 09 Aug 2012
Using custom icons can be a little tricky in WPF. It's simple enough if you want to use your application's main icon or an icon file that you can refer to using a pack URI - so long as you do that, everything just works.
Read more...Extracting Icons from PE Files 09 Aug 2012
There are times when you need an icon file, but all you have is an icon resource embedded in a PE (executable) file. Getting at these is a little tricky, since icon files aren't stored as a simple blob in the PE file. In fact, they're split up into a number of different entries. Fortunately, it isn't very hard to combine these entries into an ICO-format data blob which you can then save to file or pass to an API that expects it.
Read more...Working With Win32 Resources in .NET 09 Aug 2012
Most native applications make extensive use of Win32 resources. While the .NET Framework provides a far more useful resource API, it's sometimes necessary to access the old style Win32 resources. Fortunately, this isn't very difficult.
Read more...April
Windowed Fullscreen 30 Apr 2012
Windowed (fake) fullscreen is probably my favorite graphics option ever when it comes to PC games. It lets me have my nice fullscreen game, but doesn't lock me out of using my other monitor, and any programs running behind the game are an instant ALT+TAB away. Games that can go from fully windowed to fake-fullscreened in an instant are also super cool, and not all that difficult to write. So how does one implement such a thing?
Read more...Visual C#: Phantom Breakpoints 23 Apr 2012
So I've got a large solution with a lot of projects (mostly build tools) and every now and then I would get suspicious phantom breakpoints, meaning that the debugger would break where no breakpoint had been placed. This would usually happen after closing and reopening the project, and it only ever seemed to afflict the executables in my solution - never the libraries.
Read more...Getting Started with OpenSL on Android 23 Apr 2012
Edit: This article, as originally posted, has an error in it, which has been corrected. Anyone who just wants to see the fix can check out this update.
Read more...March
Abstracting Low-Level I/O 30 Mar 2012
One of the common requirements in game development is that we need to load large blocks of (usually) compressed data in as little time as possible. This, however, is somewhat easier said than done. Ideally, what we're looking for is a simple asynchronous I/O API.
Read more...Simple Digital Signatures 28 Mar 2012
One of the things that comes up when sending data over the internet is verifying that it hasn't been corrupted. This is generally a simple thing to resolve: send the data and a good hash (MD5 or SHA-1) of the data together. Recompute the hash on the client side and compare it to the hash you sent. If any bits have changed, the two won't match, and you know you need to redownload the file. I suppose it's possible both the data and hash could be corrupted in such a way that they match, but if your hash function is any good then the likelihood of this happening by chance is so astonishingly low that it doesn't bear consideration.
Read more...The Player's Name vs Localization 27 Mar 2012
From a game developer's perspective, the English language is incredibly simple. Our grammar is only minimally inflected, making it easy to author strings like "@(PLAYER) runs away!" and "Give this to @(TARGET)." and use simple text substitution to replace tokens like "@(TARGET)" with the name of a player, NPC, or object as needed. There are some places where this doesn't quite work (dealing with numbers and plurals or dialog which might be referring to either males or females), but they're either uncommon or easy to ignore (in many cases it's unlikely the player will have just one of something and we can just use the plural).
Read more...February
Deferred Shading Tricks 21 Feb 2012
Deferred shading is a useful technique available on modern GPUs that allows one to decouple scene and lighting complexity. I'm not really writing a for-beginners article here. This is aimed at people who've got a basic engine set up and want to tune it.
Read more...iOS Compiler Bug: -O3 FIXES It?! 18 Feb 2012
This is officially the strangest optimization-related compiler bug I've ever seen.
Read more...Using Win32 Asynchronous I/O 04 Feb 2012
Recently wrote some asynchronous I/O code for a fast data loader. The data file was logically a stream of separate objects, so it made sense to parse it a chunk at a time. That's a situation which practically screams for asynchronous I/O. Unfortunately, it's rather hard to find a useful example on how to use the relevant APIs...
Read more...January
hqNx 07 Jan 2012
This is a quick demo project I did a few years ago for fun. It's an implementation of the hq2x, hq3x, and hq4x image upscaling algorithms on the GPU.
Read more...2011
April
iOs Compiler (Bug?): "invalid offset, value too big"
01 Apr 2011
This is a bug that's bit me a few times already. Basically, the iOS compiler fails to generate some function somewhere in the code file causing it to bail with the error "invalid offset, value too big". Problem is, it doesn't tell you which function it failed on (the numbers surrounding the error seem largely meaningless).
Read more...2010
July
June
WPF: Subtle Binding Crash 19 Jun 2010
Got a crash in, of all things, System.Windows.Controls.Primitives.Popup.OnWindowResize(Object sender, AutoResizedEventArgs e)
. A NullReferenceException
, to be precise. Ages later, it turns out that this error was actually caused by a binding operation on one of the controls in the popup failing because it was trying to instantiate itself as TwoWay
with a read-only source property. Somehow, the binding error managed to turn into the NullReferenceException
in the layout pass...
2009
October
How to Make boost::function-like Templates 20 Oct 2009
If you've dealt with Boost at all, you've certainly seen this at some point:
Read more...Texture vs. Polygon: Round 1 14 Oct 2009
I recently critiqued some work-in-progress game art for an (I guess) art student, and it struck me that it can be fairly hard for a newcomer to judge where to put their details. Some details don't work very well as geometry. Others don't work well in a texture. Knowing where to put a given mark or line is the difference between effectively using your polygon budget to produce mind-blowingly good scenes and a mess of blurry textures and too-perfect railings.
Read more...MSBuild and Visual Studio's Hosting of It 07 Oct 2009
This is an interesting issue that might have bitten you if you've been trying to get code generators to play nicely in C# projects.
Read more...August
cgConnectParameter Considered Harmful 04 Aug 2009
Hooking up a large number of shared effect parameters to a single head parameter via cgConnectParameter
is, apparently, not the intended use case. Doing so causes any cgSetParameter
call on the head parameter to become orders of magnitude slower (though the amount is proportional to the number of connected effect parameters). This is also the case when deferred parameter setting is used, which is a fairly surprising result, given that it should mean that parameter values don't force any sort of evaluation until something actually goes to read from them.