DirectX Programming with C#

  1. What is Microsoft.NET and why would I want to use it?
  2. What does DirectX do to help me make games?
  3. Setting up a development environment.
  4. Creating a simple sample.
  5. Overview of Managed DirectX.
  6. Creating a DirectX class library.
  7. Building 3D mesh objects.
  8. Movement in 3D (Matrix Transformations).
  9. Collisions
  10. Sound Effects
  11. Background Music
  12. Advanced Features: Animation, HLSL

The .NET framework is Microsoft's answer to Java. You write code, compile it to an intermediate level language which is then compiled to machine code with a 'Just In Time' compiler right before it is run. The advantages are ...
  1. The executables are fast no matter what language you write in. (VB, C#, C++)
  2. The code is 'Managed' so it can't (easily) crash your operating system.
  3. All memory usage is cleaned up as your objects lose scope.
  4. Microsoft.NET introduces the C# (c sharp or c plus plus plus plus) a truely object oriented language that combines the ease of VB, the code style of java and the strong typing of C++.
  5. Last but not least *IT'S FREE!
* NOTE: Nothing in life is free, you just pay for it in another way, but if your willing to spend some extra time finding the right tools you do not need Microsoft's Visual Studio to create C# applications.
What are your choices for a development environment?
  1. Notepad and the .NET Framework: This is the bare minimum. You write your code in a 'blind' environment and then cross your fingers and compile. If you've ever worked Java then you're probably a pro at this. The C# compiler will be install with the .NET Framework which is available from windowsupdate.microsoft.com. You may already have it so check for the folder (WINDOWS)\Microsoft.NET. The compiler will be at ..\Microsoft.NET\Framework\v(x.x.xxxx)\csc.exe. Run csc.exe /? for the command line syntax. I will show a sample of compiling this way when we build the simple sample. Optionally you can download Microsoft's .NET Framework SDK which has the help files for the C# language.
  2. A third party tool: There are a few choices out there of 'free' development environments. I have only tried WebMatrix which is designed for building .ASPX web pages but can be convoluted into a simple dev. env. Just look up C# coding in your favorite search engine to find others. Microsoft's .NET framework makes it easy to produce 'intellegent' coding environments with its built in Reflection and free compiler. I will not have examples of compiling with these third party tools.
  3. Plunk down the cash and go with Visual Studio .NET: If this is the environment your used to then there is nothing better. It takes about 5 minutes to build a windows form with menus etc.

Let's get started by creating the infamous Hello World app! We will do this in Notepad so that you understand what VS7 is adding to your project. Create a file called Main.cs. (cs stands for C Sharp. This extension naming convention is just for your benefit. You can call it anything you like.) Enter the following into Notepad:
using System;
using System.Windows.Forms;
using System.Drawing;
namespace HolaMundial
{
    public class frmHola : System.Windows.Forms.Form
    {
        private System.Windows.Forms.Button btnHola;
        public frmHola()
        {
             this.btnHola = new System.Windows.Forms.Button();
             this.btnHola.Location = new System.Drawing.Point(100, 50);
             this.btnHola.Name = "btnHola";
             this.btnHola.Size = new System.Drawing.Size(64, 32);
             this.btnHola.Text = "Hola";
             this.btnHola.Click += new System.EventHandler(this.btnHola_Click);
        }
        [STAThread]
        static void Main() 
        {
            Application.Run(new frmHola());
        }
        private void btnHola_Click(object sender, System.EventArgs e)
        {
            MessageBox.Show("Hola Mundial!");
        }
    }
}
What was all that about?
Let's break it into sections.
  1. : A namespace is just a wrapper to keep your function named 'Init' from colliding with the 'Init' function of another object. So if I have 1