mort8088 Just another WordPress site


MDX 9 – Tutorial 1

Originally Posted 2006

New Project

Ok you've installed the SDK and #Develop, now what?

When you first start #Develop you are shown its start page, click on the "New Combine" button(why combine?).

You'll see the New Project dialog like fig. 1. Select C# under Categories and Direct3D Application under Templates. Enter a name for your project and click create.

Now press F5 to run the project it will compile and show you a application window with a blue background. Well done you just built your first DirectX program are you excited yet?

Didn't think so, but at this stage you have made a tiny step on the road to writting games theres still a long way to go.

Next we'll take a look at what you get to start with in the basic project. starting in the same place as the compiler with the main entry point.

The main function is rather basic in that its only perpose is to create an instace of your application class do any preperation then show and run it. don't worry if you don't understand what these functions do I'll be explaining the ones you need to know about as we go along.

Starting with the definition of the application class, as you can see the main class inherits from the Form Class so there are a lot of Methods, propertys and Events that have already been written that you have access to if you want them.

Lines 22-26 contain the MainClass constructer that was automaticly called from line 122 of the Main function this sets some basic propertys of the Form like the size of the window and the title that will appear on the task bar.

Now on to something more interesting, Initializing the Graphics system.

As you can see there is basic error handaling in the project template in the form of a try...catch if any of the code in the try block fails for what ever reason then the program flow jumps to the apropriate exception catch block, in this case we are only expecting "DirectXExceptions" if anything else goes wrong then the program will still crash.

Looking at lines 32 to 34 this is the PresentParameters for the device that we are about to create PresentParameters are a collection of properties that we want to applie to the device things like if it should be fullscreen or not, how is the backbuffer used, what format the zbuffer should be in, and do we want light effects, for your first application the ones here are good enough.

Line 37/38 is the creation of the device you can think of this as the screen output, well a class that you will use for screen output, the paramiters are a bit vague so here is the MSDN explanation.

adapter System.Int32
Ordinal number that identifies which physical device the object represents. Device 0 is the default device. The highest value that can be used in this parameter is one less than the total number of physical devices.
deviceType Microsoft.DirectX.Direct3D.DeviceType
Member of the DeviceType enumerated type that denotes the desired device type. If the desired device type is not available, the method fails.
renderWindow System.Windows.Forms.Control
Pointer to an unmanaged (or non-Windows form) window handle.(Dave edit-I didn't say it would make sense)
behaviorFlags Microsoft.DirectX.Direct3D.CreateFlags
Combination of one or more options that control device creation.
presentationParameters Microsoft.DirectX.Direct3D.PresentParameters[]
[in, out] Pointer to a PresentParameters object that describes the presentation parameters for the device to create.

If you under stood all that, why are you reading this???

Lines 40 to 43 add some event handalers that you will need to use in the future but ignore tham for now 🙂

The next function is realy where you arer going to do a large part of work the run function.

In the beginning this is a fine game loop that works well for the begginer BUT it's no good for a project of any real size, there are currently a number of discutions going on over the internet on what is the best way to construct the perfect game loop, but untill one has been agreed then this is what I'll be working with.

The basics of this function as it stands is this :-

  1. While the user has not quit the application continue.
  2. Move whatever needs to be moved.
  3. Draw whatever needs to be drawn.
  4. Proccess any windows events.

Both FrameMove() & Render() contain nothing that can't wait untill we start on the render engine, so untill next time...

Comments (0) Trackbacks (0)

Sorry, the comment form is closed at this time.

Trackbacks are disabled.