Updates

Latest Tweet



What's New?

Check out for latest innovation, a computer based training video collection


Like this Page

Introduction to 3D Game Programming with DirectX 9.0 (Wordware Game and Graphics Library) Review by David Emmith

A very good introductory book

This review covers the first 13 chapters. It is a book that you will definitely learn from; however, beware that it is not written for users of C#. C# samples can be downloaded from the book's web site and I talk extensively about that in this review. This review is more a How-To than anything else - it documents my experience with the book and using the sample code from the book's web site. I am new to 3D game programming so I started out with giving myself a crash course in Linear Algebra (for this I studied the book, "3D Math Primer for Graphics and Game Development").

In Part 1 the author could do a better job of explaining how a vector cross product is calculated. He refers to "formula (4)" which is a formula in final form (i.e. it does not show the steps). Furthermore, "formula (4)" comes seven pages after the first three formulas, so when you come to "(4)" (on page 13) you may have already forgotten about (1), (2) and (3) (which are on page 6) -- it is awkward. It should be highlighted and labeled as "FORMULA 4:" or something like that.

In Part II, Chapter 1 (Direct3D Initialization), section 1.4.1 describes initializing a pointer to an IDirect3D9 interface as...
IDirect3D9* _d3d9;
however, in section 1.4.2 the code for checking the capabilities of the primary display adapter shows this code...
d3d9->GetDeviceCaps...
The underscore character is missing from the IDirect3D9 object. It should read...
_d3d9->GetDeviceCaps

The source code can be downloaded from http://www.moon-labs.com/ml_book_samples.htm. C# versions of the sample programs are available. The download instructions include a username/password but I was able to download the files without having to provide them. Should you be prompted for a username/password the author's instructions state, "The user name is exactly the second word on page 212 in the first paragraph of Chapter 13. The password is exactly the fourth word on page 213 in the first paragraph of section 13.1." Let's cut to the chase, its "terrain/heightmap" (without the quotation marks or forward slash).

The code in the book is meant to be used in a C++ development environment. I use C# 2005 Express Edition therefore there wasn't anything I could do with the code in the book. When you open a sample code project (one from the C# versions available at the web site) in the C# 2005 Express Edition, a "Visual Studio Conversion Wizard" will prompt you to convert the project to the current edition's format. Just go ahead and click on "Finish." As I mentioned in a previous paragraph, there is a C# version of the sample programs provided on the web site.

Beginning with Chapter 3's sample and in all of the samples I could not understand why the 'Window' parameter would not work the way I understood it to work. In Form1.cs, when a d3d object is instantiated with a 'true' instead of 'false' for the Window parameter (the 3rd parameter), nothing worked. This works...
d3d = new D3DInit.D3DInit(800, 600, false, DeviceType.Hardware, ref device);
but this does not...
d3d = new D3DInit.D3DInit(800, 600, true, DeviceType.Hardware, ref device);

I had trouble with the sample for Chapter 6 (Texturing). The problem was due to the sample program's inability to find the texture image. To fix it, all I had to do was change the source code to reflect the FULL path to the image file. I'll clarify... this is the original line 136 in D3DInit.cs...

tex = Microsoft.DirectX.Direct3D.TextureLoader.FromFile(device, "dx5_logo.bmp");

I modified it to...

tex = Microsoft.DirectX.Direct3D.TextureLoader.FromFile(device, "D:\\david.emmith\\Books\\Intro to 3D Game Programming\\Part II CS\\Chapter6\\dx5_logo.bmp");
(Note: Remember to escape backslashes in path names by making double-backslashes, otherwise you'll get an error.)

The same problem occurred again in Chapter 7's sample.

In Chapter 11's sample you may find a similar problem to the ones I described above for Chapter's 6 and 7. In Chapter 11 there is a line in D3DInit.cs (line #55) that reads...

private string shipFilename = "bigship1.x";

You may need to modify it to reflect the full path name.

If you are writing your own app and using the .NET samples as a guide you may run into a few problems when you build the solution. You may see a "... has more than one entry point defined" error. This will happen if you have the following code in your Form1.cs file...

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

There is no need to have those lines in your Form1.cs (or whatever filename you are using in place of Form1.cs). A Program.cs file should have automatically been created in your project (click on the 'Show All Files' icon in Solution Explorer). You can do one of two things to rectify this problem:
(1) Comment out or delete the code shown above in your Form1.cs (or its equivalent) file.
*** OR ***
(2) Exclude Program.cs from your project (right click the Program.cs icon and select 'Exclude From Project').

There is a similar situation in the D3DInit.cs file. There is no need to include the Dispose() method - it will already be in the D3DInit.Designer.cs file (this file, like Program.cs, is automatically created by the Visual C# IDE).

Another problem you may encounter if you are trying to use the Esc key to terminate your DirectX app is the Esc key not working. To solve this problem open your Form1.Designer.cs file and add the following line at the end of the InitializeComponent() method...
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp);
Then make sure you have this method in your Form1.cs file...

private void Form1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
d3d.CloseD3DInit();
Close();
}

And of course your D3DInit.cs file should have the CloseD3DInit() method defined. If not it should look like this...

public void CloseD3DInit()
{
displayThread.Abort();
Close();
}

In Chapter 11, as I mentioned earlier, there is a reference to a file named bigship1.x which is provided in the sample project. This is a mesh file which is nothing more than a geometric description of an object - in this case, a spaceship. If you're like me and you want to workout your own example you would like to create your own mesh file and test it in your own application. To create a mesh of your own design you will need the aid of a program. DirectX uses the .x file format for its mesh files. Some of the more popular 3D design programs do not readily provide a method for turning their meshes into the .x format. I will describe as briefly as possible the steps I took to create a simple mesh, convert it to a .x file and use it in my own program. There is probably a better way but this is the way I did it.

(1) Find a FREE 3D design program. I downloaded and installed two programs:

(a) Maya 7.0 Personal Learning Edition

(a.1) Can be found at the Autodesk web site.

(b) Autodesk 3DS Max 9 (30-day trial)

(b.1) Can be found at the Autodesk web site.
I was more interested in 3DS Max because I have my eyes on some aircraft models I want to use and they were created in the .max file format. So this is the program I used to create a very simple model.

(2) Create a model. I created a sphere with a green texture in 3DS Max. I won't go into the details of how I did that because it is not that difficult to figure out on your own. You may want to create something a little more 'elaborate' than a green sphere. Have at it.

(3) Convert the model into an x-file. This sounds simple enough but try doing it on the cheap, i.e. $0.00.

(a) If you want to pay for a conversion utility up front then check out two products from Okino Computer Graphics:

(a.1) NuGraf

(a.2) Polytrans (a simpler version of NuGraf)
It should be noted that Robert Lansdale (lansd[at]okino.com) offered to do a one-time conversion for me. I emailed him my .max file and he sent me back a .x file. I had already done the conversion by the time he sent the file back but I certainly appreciated his kind gesture.

(b) If your cheap like me you want to do this for free because afterall, you're just trying to learn how all this works. I contacted a 3D guru by the name of Chad Vernon. Chad was very helpful in pointing out a couple of free conversion tools:

(b.1) kiloWatt X file Exporter

(b.2) Pandasoft's Panda Xporter Tool

(c) I used Panda Xporter. After you unzip the .zip file you have a file named PandaDirectXMaxExporter.dle. This is a 'plugin'. So what you need to do next is to make this file known to 3DS Max and the way you do that is place the file in 3DS Max's plugin folder. On my machine this folder is located at D:\Program Files\Autodesk\3ds Max 9\plugins. Now you are ready to convert your model to the .x file format.

(d) Launch 3DS Max (close the Welcome Screen if it appears) and open your model file (File | Open Recent). The first time I did this with the Panda Xporter in place 3DS Max crashed. I removed the Xporter from the plugin folder and re-launched 3DS Max. It crashed again. I eventually got it to work and put the Xporter back in the plugin folder. 3DS Max did not crash after that. This remains a mystery. The problem appeared to have fixed itself.

(e) Select File | Export. Click on the down arrow for 'Save as type' and choose Panda DirectX (*.X). Click in the 'File name' textbox and enter a file name without a file extension. Note where the file is being saved to. You will need to know the full path to your .x file when you create your own 3D app. Click on 'Save'.

(f) In the 'PandaSoft DirectX Exporter' dialog, '3DS Max Objects' tab, uncheck 'Include Animation' if your object is not animated. In the 'XFile Settings' tab, the 'DX File Type' of either 'Text' or 'Binary' worked for me. I believe the default is text. Click 'OK'.

(4) Create your own 3D app. Again, I am using Visual C# 2005 Express Edition. Use the C# samples provided at the book's web site to guide you. Remember, as I have pointed above, that there are some differences that come into play between the samples and what you create in a Visual Studio 2005 environment. Read through my earlier comments.

I hope this helps. Now on to the review.

In Chapter 12's sample, line #138 of D3DInit.cs needs the full path to dx5_logo.bmp. I described this same problem in earlier chapter reviews.

In Chapter 13's sample, line #601 of D3DInit.cs refers to a temp.raw file. This file, as far as I can tell, is not included in the managed (.NET) sample files. So I came up with my own work around which I describe below...

(1) Download Terragen which is a free terrain generation tool. Look for the link labeled, "Install Terragen v0.9.43 (1.6Mb)" in the download page. Now install Terragen.

The following steps are for once you have launched Terragen.

(2) Click on the 'Landscape' icon in Terragen and then click on the 'Generate Terrain' button.

(3) Click on the 'Export' button.

(4) In the 'Terrain Export' dialog click on the 'Export Method' dropdown listbox and choose 'Raw 8 bits'.

(5) Click on the 'Select File and Save' button and choose the name for your .raw file and its location.

Now that you have your own raw file you can insert the file's full pathname into the Chapter 13 sample.

If you have found or already have Terragen .ter files you can convert them to .raw files with a little free utility named 'Terrify'.

The book's web site has some additional information pertaining to Chapter 13. You can go to the Resources page and scroll down to 'Basic Terrain Rendering Part II'. The 'Download Code' link will give you a file named 'TexBlendTerrain.zip' which, according to my WinZip utility, is not a recognized Zip file. The links in 'Remark 2' do not work (they take you to some useless page).

This is the extent of my review. This is a very good book but I wish it were geared towards .NET developers.