XNA for C#
DirectX 9 for C#
DirectX 9 for C++
DirectX 9 for VB
Forum
   
My XNA Book
      
       Go to section on this site

Additional info


Latest Forum posts

 Account settings
  Posted by: Anonymous
  When: 07/05/2014 at 09:48:39

 forced subtitle
  Posted by: Applefly
  When: 07/05/2014 at 06:00:48

 convert DVD into PMS
  Posted by: Applefly
  When: 07/05/2014 at 05:55:25

 DVD to Digital Copy easily
  Posted by: VIKIVannessa
  When: 05/05/2014 at 06:52:29

 DVD on Xbox 360/Xbox One Console
  Posted by: VIKIVannessa
  When: 05/05/2014 at 06:51:47

 Extract .Srt Subtitles
  Posted by: Applefly
  When: 04/05/2014 at 03:54:38

 Encode Movie collection
  Posted by: Applefly
  When: 04/05/2014 at 03:52:41

 Convert DVD to WMV
  Posted by: Applefly
  When: 29/04/2014 at 05:53:50

 rip DVDs into digital files
  Posted by: Applefly
  When: 29/04/2014 at 05:51:20

 iTunes movies/music to Kindle Fire
  Posted by: ciciyu80
  When: 29/04/2014 at 05:10:20


Ads

Opening your project window

Welcome to the first entry of the Managed DirectX 9 Tutorial. This tutorial is aimed at people who haven't done any 3D programming so far and would like to see some results in the shortest possible time. To this end, C# is an ideal programming language. C# is a relatively easy language, so anyone who has some basic programming experience should be able to start right away. Even more, this tutorial is written in such a way that anyone who has any programming experience should be able to understand and complete it.

The required software to start writing your own DirectX 9 code :

  • A C# programming environment. Popular is Visual Studio .NET, but you can also download the free evaluation version of Borland C# Builder. Recently, Microsoft has released a free version of Visual Studio, Visual Studio Express, which you can download here: (link)
  • The .NET framework. (free) (link)
  • And of course the DirectX9 SDK. (free) (link)

    With all this software installed, you can start a new C# Application. To do this in Visual Studio, click the File menu and select New. As project type, we of course need Visual C#. Now on the right, you can select Windows Application. Fill in the name, and hit the OK button!

    Now you should see a small empty form. To switch to the code, find Program.cs at the right of your screen. Right click on it and select View code. Next, you should add a reference to Microsoft.DirectX and to Microsoft.DirectX.Direct3D. This is how you do it: in Visual Studio, go to the Project menu, and select ‘Add reference…’. In the list that comes up, pick Microsoft.DirectX and Microsoft.DirectX.Direct3D. Be sure NOT to select DirectX version 2.0. Also add the following lines to you using-block, so your program can use the referenced libraries:

     using Microsoft.DirectX;
     using Microsoft.DirectX.Direct3D;

    Compiling this will already give you an empty form. Now we want to change the size and the title of it. To do this, simply find the InitializeComponent() method and change the size to (500,500) and the title (= this.Text) to "DirectX Tutorial" or whatever you like.

    Next we are going to change the Main() method a bit:

     static void Main()
     {
         using (WinForm our_directx_form = new WinForm())
         {
             Application.Run(our_directx_form);
         }
     }

    You are now ready to start programming with DirectX! Compiling this code should give you a small form.




    DirectX Tutorial 1 - Opening a window

    If you appreciate the amount of time I spend creating and updating
    these pages, feel free to donate -- any amount is welcome !



    Click here to go to the forum on this chapter!

    Or click on one of the topics on this chapter to go there:
  • visual studio 2010 hangs
          Hi,as soon as i put the references in c# program.c...
  • Form size without border
          Hey When I change the form size to 640x480 the wh...
  • Get Started
          I have Windows 7, DirectX SDK, and VS 2010. How...
  • Visual C# Epress 2010 and references
          Hello, i have been wanting so badly to follow you...
  • Problem with Opening the WinForm
          Hello, im trying to Open a Form in a DirectX9 Gam...
  • WinForm not found
           using System; using System.Collections.Ge...
  • download links outdated
          Hey Riemer The links on this page have expired ...
  • System.BadImageFormatException
          I'm working on a 64bit laptop and just installed ...
  • Add Reference to Microsoft.Direct3D
          Hi, I'm new to Game development, but have been us...
  • Microsoft.Samples.DirectX.UtilityToolkit
          (Hey the topic is exactly 40 chars! And sorry if t...
  • Opening your project window
          K been stuck on this for hours now lol. I cant ma...
  • Build Error
          When im done with the code and debug i get a build...
  • not win 32 application
          Helo, I have visoual studio 2005 prof edition, ...
  • Why am i gettin CMD window...
          Why am i gettin CMD window... i dont want the cons...
  • Run .exe file
          Hi, I'm a C# n00b, I have followed this tutorial...
  • WinForm or Form?
          I'm not sure if this is right, but using Visual S...
  • starting
          yes when i create the windows application in the c...
  • Linking Errors
          Hi, I'm using VSC++ 2005. The program compiles, ...
  • Linking Errors
          Hi, I'm using VSC++ 2005. The program compiles, ...
  • initialize component method
          where is the initialize component() method? The on...
  • Problem...
          When I put in all the code that you said, I got th...
  • where should I start write code?
          Hello, I am new in DirectX programmin. I am using...
  • Error..
          Hi, when i type : using Microsoft.DirectX.Di...



    After each chapter I will list the whole code so far, so this is what you should have by now :

     using System;
     using System.Drawing;
     using System.Collections;
     using System.ComponentModel;
     using System.Windows.Forms;
     using System.Data;
     using Microsoft.DirectX;
     using Microsoft.DirectX.Direct3D;
     namespace DirectX_Tutorial
     {
         public class WinForm : System.Windows.Forms.Form
         {
             private Device device;
             private System.ComponentModel.Container components = null;
             public WinForm()
             {
                 InitializeComponent();
             }
     
             protected override void Dispose (bool disposing)
             {
                 if (disposing)
                 {
                     if (components != null)
                     {
                         components.Dispose();
                     }
                 }
                 base.Dispose(disposing);
             }
             private void InitializeComponent()
             {
                 this.components = new System.ComponentModel.Container();
                 this.Size = new System.Drawing.Size(500,500);
                 this.Text = "DirectX Tutorial";
             }
     
             static void Main()
             {
                 using (WinForm our_dx_form = new WinForm())
                 {
                     Application.Run(our_dx_form);
                 }
             }
         }
     }
     


    Google
     
    Webwww.riemers.net


    If you appreciate the amount of time I spend creating and updating
    these pages, feel free to donate -- any amount is welcome !



    - Website design & XNA + DirectX code : Riemer Grootjans -
    ©2003 - 2011 Riemer Grootjans
  • Translations

    This site in English
    This site in Korean
    This site in Czech

    Microsoft MVP Award



    2007 - 2011 MVP Award
    DirectX - XNA

    Contents

    News
    Home
    Forum
    XNA 2.0 Recipes Book (8)
    XNA 3.0 Recipes Book (8)
    Downloads
    Extra Reading (3)
    Matrices: geometrical
    Matrix Mathematics
    Homogenous matrices
    Community Projects (1)
    Tutorials (160)
    XNA 4.0 using C# (89)
    DirectX using C# (54)
    Series 1:Terrain (14)
    Opening a window
    Linking to the Device
    Drawing a triangle
    Camera
    Rotation - Translation
    Indices
    Terrain creation
    Terrain from file
    DirectInput
    Importing bmp files
    Colored vertices
    DirectX Light basics
    Mesh creation
    Mesh lighting
    Series 2: Flightsim (19)
    Series 3: HLSL (19)
    Short Tuts (2)
    DirectX using C++ (15)
    DirectX using VB (2)
    -- Expand all --


    Thank you!

    Support this site --
    any amount is welcome !

    Stay up-to-date

    I don't have the time to keep a News section, so stay informed about the updates by clicking on this RSS file!