I’ve been trying to just build things rather than get bogged down in designing too much up front and not worry about making code that runs cross-platform. Despite this, the latter is something that has always been something I try to think about because I don’t like being tied down to one particular operating system. I currently develop in Mountain Lion using XCode for my IDE, but I want anything I write to be runnable on at least Windows as well and Tetris is no exception.

Code should be written in such a way that the bits that touch the operating system are abstracted away from actual application logic regardless, but what’s been particularly useful for me as a newcomer to writing games is the GLFW framework as it takes care of this entirely. It’s meant I haven’t had to write any OS-specific code for windowing or OpenGL context creation. It doesn’t prevent me from being a C++ newbie and being unfamiliar with compiling and linking on the platforms that I port to, however.

On this note, having recently rebuilt my Macbook, I’d removed my Boot Camp partition which is where I’d previously debugged the Windows version of Snake. A major downside to having an extra OS on a partition on a laptop is that it takes up a lot of space - a vanilla install of Windows 7 takes up 10 gigs, and a fully updated one closer to 30. On my ageing macbook, that’s a substantial portion of the disk space so I decided to look at creating a Windows Virtual Machine instead.

I use Linux VMs at work most days and I’ve used Windows ones in the past for browser compatability testing, but I’ve never created one myself. Historically I’ve used VMWare products, but recently at work we’ve been encouraged to switch to VirtualBox for licensing reasons. VirtualBox is absolutely brilliant. I ran across a problem where I didn’t seem to be able to create the VM using my Mac because I wasn’t able to create any file system that Windows could read other than FAT32. This could have been me missing a trick, but in the end I used Lana’s Windows laptop to create the base system as it created an NTFS partition by default.

With the system built I installed all the MinGW and MSYS tools to make the system dev-worthy, as well as git so I could clone from my repos that I store on my Linode VPS. I then obtained Visual Studio 2012 Express for C++ development (though I may consider using the MinGW ports of GCC when I’m competent). I also ran all of the Windows updates which took a whole day and increased the OS footprint by 20 gigs. That was an interesting stat to see!

Compiling and linking C++ programs is something that I always have to relearn. Perhaps I’m just spoiled by the incredible Java IDEs we have these days and take for granted the fact that the JVM abstracts away platform issues - it’s probably more likely the lack of practise. In any case, it took a bit of work to get the version of Tetris to run that I’d built so far. For a start, the x64 version of the library don’t appear to work on my VM which was running the 64 bit version of Windows 7 though I didn’t dig deep enough to find out why and settled with the x86 version which did work. In addition, I always find slight differences in what the compilers deem acceptable, despite allegedly adhering to the same spec, so there’s always a period of adjusting lines of code here and there to get the thing to compile on a new OS.

When the application had successfully built, I tried running it but it failed instantly. The GLFW Window refused to create. There wasn’t any useful debug that I could ascertain at this point, but I suspected that the VM being a VM, may not support OpenGL. At least not out of the box. I ran the build on Lana’s machine and it worked fine (for a work in progress anyway). So I did some reading and learned that VirtualBox has something called Guest Additions that need to be installed for certain aspects of functionality to be enabled. With these installed, the build worked with only an odd glitch with the window not quite aligning with its frame.

In conclusion, I’ve now got a VM running Windows 7 on which I can debug my application and not be tied down to my Macbook as it lives on an external hard drive. I also have a build of the version of Tetris that is currently in progress running on Windows just like it does on my Macbook Pro. That’s a positive result for the weekend, and I’ve learned a lot about VMs and setting Visual Studio up while doing it.

Another gain from the last week or so has been increased usage of git. I’m trying to maintain a clean trunk in my tetris repo and use feature branches for new functionality. I made my fixes and added the VS project to a branch called ‘windows-init’ and merged this back to trunk after it was clear that it did not affect the Mountain Lion build.