Game tools have long been overlooked as an important piece of the development process. Many hobbyists and professional programmers have difficulty putting forth effort on a complete tool package, coming from a world where glorious hacks are applauded. Existing software can be supported through command line applications or file parsers, and artists can adapt to a few extra steps in the process. Many feel that their time is best spent doing "important" things, rather than squandering it all on a tool set that will never see the light of day. GUI layout and other "fluff" add tedium to the process, further frustrating the programmer. Further more, windows applications have a sort of mystique for those that are new to tool development, often times leading to intimidation and rationalization about the subject.
No problem. Using APIs like OpenGL or Direct3D (which most programmers are already familiar with) and MFC, tools can be written quickly and efficiently. More often than not code can be taken directly from the game engine and dropped right into the framework, not only saving time but maintaining consistency between the way scenes are displayed in-game and in the tools.
Who is This Article For?
The purpose of this article is to provide a lightning quick introduction to MFC and dive into 3D tools. Prior knowledge of MFC is not required, but a cursory knowledge of the MFC architecture is highly recommended. The accompanying source uses OpenGL for rendering, although other APIs can be similarly implemented. MFC is also heavily rooted in C++, so those that donít subscribe to the object-oriented school of thought might want to read this article with a reference book in their lap. I also recommend referring back to the MSDN library throughout the course of all your projects, as I canít possibly provide the amount of detail found therein.
Obviously this subject has the potential to be overwhelming and huge, so Iíll only be covering a fraction of the process here. However if there were an expressed interest in future articles along the same vein Iíd be happy to comply.
Still here? Let the good times roll...
So after all that, what the hell am I talking about? For those that skipped their anachronism class in high school, MFC stands for the Microsoft Foundation Classes. As this is nearly as cryptic as the abbreviation was, Iíll elaborate. Simply put, MFC is a set of C++ classes that attempt to simplify the process of creating GUI applications for windows. Alone itís not much to look at, but combined with an uncharacteristically helpful wizard and a useful set of editors it becomes a very powerful tool. For purists MFC is viewed as an unneeded abstraction, and ranks right up there with Mr. Rogers and Hitler. Despite arguments to the contrary MFC can save you weeks of tedious guess and check coding, so if you can leave your hang-ups at the door weíll all get along better.
The following are some terms that are used freely when discussing MFC:
Control: A GUI object that allows the user to control or modify the document or application in some fashion (text field, checkbox, dropdown list, button, etc).
Document: All the data that is contained and created by your application (the text in a word processor, a scene in a 3D modeler, etc).
View: A particular way to display a document or set of controls in your application.
SDI: Single Document Interface - an MFC application with a single document and a varying number of views.
MDI: Multiple Document Interface - an MFC application with many different types of documents and a varying number of views.
In our case weíll only be looking at SDI applications that use the document/view philosophy. Most applications can easily be split into a single document and multiple views - especially in the case of a one-track tool like a level editor. Although itís possible to create an MFC application without using documents or views it is more time consuming and generally less effective unless your application is very simple. This is just a taste of MFC terminology, so I still recommend reading through some of the MSDN entries on the subject. Weíll also be using the class wizard and the resource editor to maintain our application during development, so make sure youíre familiar with them, as I wonít be describing them in depth. Once again the MSDN library has many helpful entries on both tools.
Before We Start...
For this article we will be creating a simple 3D-model viewer. The layout will include four viewports to display the model in either a variety of orthogonal views or a perspective view. There will also be a bar of controls used to change each viewportís type. The file format will be *.md3 files (Quake III Arena model files), however there will be little time spent on the actual model loading and drawing, as the general architecture is our focus. I chose the *.md3 file format simply because I had some old code from another project lying around and I didnít feel like spending the time on another file format. Itís recommended that you download the accompanying source package.