|
Learning to Program for Addiction (or, Game Programming 101)
So you’re into games, eh? You’ve chosen to forgo social interaction, exercise, and sunlight to live in a virtual world where you have saved 12 million gold, have conquered the entire American continent, and hold the trophies for too many fighting tournaments to count. You’d much rather plant a few more SimBushes than do actual yard work. You’ve spent 1237 hours behind the wheel of a Cessna, but have yet to attend a single flight class. You, my friend, are a gamer, and you’ve come to the right place.
I was at a bit of a loss as for what to write about this month. We all know the old adage – you can’t please everyone. I could write a tutorial on getting a window up and running in DirectX, or I could write a review of a game I’ve recently played, and half of you would be upset either way. So I thought I’d compromise. The first half of this article is going to be a set of resources for those of you interested in getting up into your elbows in code – that small segment of the population who would much rather spend their nights writing that slick terrain-generation algorithm than sleep. And the latter half I’m going to devote to resources for those of you who want the hard product – you just want to beat Bowser as quickly as possible, and you don’t care why it happens. This will largely be the format you’ll see from me – half technical, half superficial. Expect a new tutorial each month, and a new review of a game or technology that piques the interest of the masses. No hard format, just games (or something like them). So let’s get started.
Tech Corner – All the Resources you could Never Want
Let’s get one thing out of the way, first – Google. It is the beginning and end of every self-taught gamer. If you don’t grasp a concept, or if you’ve been hunting for the same bug for the past hundred hours, there’s a good chance that you’re not the first to encounter similar difficulties. But since this is a primarily technical magazine, I’m sure most of you already know that – so I’ll take down the billboard.
The web is a fantastic resource for those of you wanting to learn games. I’ll be covering a new set of topics every month, with the goal being to provide the uneducated with the tools to create a better game every month. You, the reader, will judge whether or not that goal is met. But for now, if you’re a little too eager to get going, there are a slew of websites devoted to the training of new game programmers. Note – most of these will not cover programming language basics. You can pretty much write a game in any computer language, but first you have to learn a language. Don’t worry, the days of hacking the video card with ASM to squeeze that last ounce of color out are pretty close to gone – at least, I won’t be covering them (yet). I’m going to do most of my work in C++, because bitblt in VisualBasic can be very annoying (not to mention that VB is typically too poorly optimized for efficient game programming), and I don’t know java well enough yet (still taking classes) to do more than put a few buttons in a swing frame. Additionally, I come from an OpenGL background, but fear not! In an effort to demonstrate how flexibility is the life or death of the game programmer, I will do my best to provide DirectX code equivalents for all of my OpenGL code. I’ll be more or less learning parts of the DirectX API as I go along, so you may have to bear with me in a few places.
The only things a game programmer needs are a text editor and a compiler. Whether it is a Pico-like editor and GCC or a full-blown IDE, you can’t do much of anything without something to translate the code into an executable. There are plenty of decent compilers out there, but most of them aren’t cheap. If you aren’t a lucky student (like me) who can get Visual Studio.NET for free from school (Don’t worry MVPs – it’s the MSDNAA, not piracy), you’ll probably want to opt for a freeware version. Some of the more prominent ones, and where they can be found, are:
- MinGW Studio for Windows – http://www.parinya.ca/ - A free IDE based off of MinGW (Minimalist GNU for Windows) – has much of the look and feel of Visual Studio, without all the costs
- DJGPP - http://www.delorie.com/djgpp/ - for those of you out there who firmly believe that GUIs ruin productivity, this freeware compiler is for you.
- Cygwin – http://www.cygwin.com/ - Not really a compiler, but it comes with several compiler packages. This program more or less emulates a Unix terminal on a Windows machine, giving you all the joys of VI and GCC without the pain of reformatting and partitioning
You’ll also need some SDKs to get started programming in various graphics. The core of OpenGL is included in most modern video cards, but can be found if you’ve got nothing better to do. Aside from that, you’ll need:
For OpenGL:
- GLUT - http://www.xmission.com/~nate/glut.html - The GL Utility Toolkit. This library makes things like creating a window and drawing certain 3D shapes a snap. Free for download, licensed under the GPL
- SDL – http://www.libsdl.org - another interface library for OpenGL, this one gives you a bit more flexibility than GLUT, but is also still under development (thus maybe a little buggy), and can be a bit confusing to set up at times
For DirectX:
- Microsoft’s DirectX SDK – http://www.microsoft.com/ - The DirectX SDK is available for free download from Microsoft.com, just check out their downloads section, select DirectX as the Product/Technology, and find the DirectX 9.0 SDK with 9.0b runtime (note that this number changes roughly once a year as updates are made to the DirectX SDK)
Probably the last thing you’ll need is a good reference on each of these graphics APIs. For OpenGL I recommend The OpenGL Programming Guide, Third Edition, known as the OpenGL “red book”, and any books on 3D graphics programming you think you may need. For DirectX, André LaMothe has a pretty good book in Tricks of the Windows Game Programming Gurus, which covers much of the set up and use of DirectX, as well as what little MFC programming you’ll need to get your window up and running.
Finally, there are literally hundreds of tutorials available on various websites around the net. The ones I tend to surf are:
Tune in next month when I cover the basics of setting up the window, the game loop, and drawing to the screen. If you’re that special brand of coder who just can’t wait a month (YOU know who you are :-P ) I highly recommend you check out the above sites and work through some of the tutorials.
|
|