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

 Tutorial 3 for Windows Phone 7
  Posted by: Anonymous
  When: 20/05/2013 at 02:30:13

 No download link for 2d series: shooter
  Posted by: zaboleq
  When: 07/05/2013 at 15:46:28

 Collision Class?
  Posted by: Anonymous
  When: 05/05/2013 at 19:03:59

 stack overflow
  Posted by: cityguy
  When: 07/04/2013 at 01:58:38

 Meshes looks strange.
  Posted by: ab_saratov
  When: 01/04/2013 at 04:31:08

 Lamppost Not loaded
  Posted by: Anonymous
  When: 22/03/2013 at 06:43:52

 Collision Class?
  Posted by: Da_Boom
  When: 21/03/2013 at 01:23:09

 Math boggles me
  Posted by: cityguy
  When: 17/03/2013 at 03:44:48

 Collision Class?
  Posted by: Da_Boom
  When: 16/03/2013 at 03:44:42

 Tree update
  Posted by: Anonymous
  When: 15/03/2013 at 21:11:22


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:
  • 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)
    Chapter 1
    Chapter 2
    Chapter 3
    Chapter 4
    Chapter 5
    Chapter 6
    Chapter 7
    Chapter 8
    XNA 3.0 Recipes Book (8)
    Chapter 1
    Chapter 2
    Chapter 3
    Chapter 4
    Chapter 5
    Chapter 6
    Chapter 7
    Chapter 8
    Downloads
    Extra Reading (3)
    Matrices: geometrical
    Matrix Mathematics
    Homogenous matrices
    Community Projects (1)
    Team Project (1)
    News
    Tutorials (160)
    XNA 4.0 using C# (89)
    2D Series: Shooters (22)
    Starting a project
    Drawing fullscreen images
    Positioning images
    SpriteBatch.Draw()
    Rotation
    Keyboard input
    Writing text
    Angle to Direction
    Direction to Angle
    Smoke trail
    Manual texture creation
    Random terrain
    Texture to Colors
    Coll Detection Overview
    Coll Detection Matrices
    Putting CD into practice
    Particles
    Additive alpha blending
    Particle engine
    Adding craters
    Sound in XNA
    Resolution independency
    3D Series 1: Terrain (13)
    Starting a project
    The effect file
    The first triangle
    World space
    Rotation - translation
    Indices
    Terrain basics
    Terrain from file
    Keyboard
    Adding colors
    Lighting basics
    Terrain lighting
    VertexBuffer & IndexBuffer
    3D Series 2: Flightsim (14)
    Starting point
    Textures
    Loading the floorplan
    Creating the 3D city
    Loading a Model
    Ambient and diffuse
    Quaternion camera
    Flight kinematics
    Collision detection
    Adding targets
    Point sprites
    Alpha blending
    Skybox
    Camera delay
    3D Series 3: HLSL (18)
    Starting point
    HLSL introduction
    Vertex format
    Vertex shader
    Pixel shader
    Per-pixel colors
    Textured triangle
    Triangle strip
    World transform
    World normals
    Per-pixel lighting
    Shadow map
    Render to texture
    Projective texturing
    Real shadow
    Shaping the light
    Preshaders
    3D Series 4: Adv. terrain (19)
    Starting code
    Mouse camera
    Textured terrain
    Multitexturing
    Adding detail
    Skydome
    The water technique
    Refraction map
    Reflection map
    Perfect mirror
    Ripples
    The Fresnel term
    Moving water
    Specular highlights
    Billboarding
    Region growing
    Billboarding renderstates
    Perlin noise
    Gradient skybox
    Short Tuts (3)
    Run XNA on older pcs
    MessageBox in XNA
    Normal generation
    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)
    Starting code
    Textures
    The floorplan
    Creating the 3D City
    Meshloading from file
    Ambient light
    Action
    Flight kinematics
    Collision detection
    Skybox
    Texture filtering
    Adding targets
    Point sprites
    Alpha blending
    DirectSound
    Sounds in 3D
    Playing MP3 files
    Displaying text
    Going fullscreen
    Series 3: HLSL (19)
    Starting point
    HLSL Introduction
    Vertex Shader
    Shaded triangle
    Pixel Shader
    Textured Triangle
    Triangle Strip
    World transform
    Adding normals
    The first light
    Shadow mapping
    Render To Texture
    Projective texturing
    The first shadow
    Shaping the light
    Preshaders
    Multiple lights
    Adjusting Z values
    Finishing touch
    Short Tuts (2)
    Resizing problem
    Checking Device caps
    DirectX using C++ (15)
    Series 1: Terrain (15)
    Opening a window
    Ending the game loop
    Linking to the Device
    Clearing your window
    Drawing a triangle
    Culling
    Camera
    Rotation - Translation
    Indices
    Terrain creation
    Terrain from file
    DirectInput
    Importing .bmp files
    Adding colors
    DirectX Light basics
    DirectX using VB (2)
    Series 1: Intro (2)
    The first triangle
    Rotation - translation
    -- Tree view --


    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!