Check out the source code behind the PIRATE Engine demo game. Beware, you will not be able to recompile unless you have the PIRATE Engine code.