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

Importing Meshes from file

In Series 1 of these DirectX Tutorials, we’ve already been introduced to Meshes. In short: a mesh is a structure that holds all necessary information to draw an object. In Series 1, a mesh was used to store the vertexbuffer and indexbuffer of our terrain. The Mesh structure has the advantage that it has some very useful methods, such as the ComputeNormalData and OptimizeInPlace methods we used in Series 1.

In addition to the indexes we stored in the Mesh, a Mesh can also hold all the Material and Texture information you need to draw an object. As an example, we could again put our whole 3D city into one mesh, have it optimized and displayed. This would yield a higher framerate, but I leave it up to you because it wouldn’t introduce any new DirectX features as we’ve already done this as well in Series 1.

It is also possible, however, to store such a Mesh structure to a file, and as such, to load a Mesh structure from a file! This is mainly what we are going to do in this chapter. So we’re going to create a generic method that loads a meshfile, from which the filename is passed as an argument:

 private void LoadMesh(string filename, ref Mesh mesh, ref Material[] meshmaterials, ref Texture[] meshtextures, ref float meshradius)
 {
 }

As you can see, all the other arguments are preceded the a ‘ref’. For the first argument, this means that the program first has to create a Mesh object. This (empty) object is passed as a whole to the LoadMesh method, which will then fill it, and the filled mesh is returned to a master program. If we didn’t put the ‘ref’, a local copy would be made in the LoadMesh method, which would then be adjusted, but when the method would finish, the local method would be thrown away and the changes would not affect the master program. The ‘ref’ way is called ‘passed by reference’, the latter ‘called by value‘. You can google on this for more information.

As you can see, our program will also receive a Materials array, a Textures array and a float that contains the radius of the Mesh loaded. This radius will later be used for collision detection. Let’s focus again on the LoadMesh method, and put these lines in it:

 ExtendedMaterial[] materialarray;
 mesh = Mesh.FromFile(filename, MeshFlags.Managed, device, out materialarray);

The FromFile method will load a mesh from the file specified in the first argument. We leave the memory management for the index- and vertexbuffers to the Managed environment. Then we need to specify our device, and pass an array where all the other information accompanying the mesh will be stored in. The ‘out’ has a meaning comparable to the ‘ref’.

So we’ll end up with the Mesh object and an array filled with the additional info. First we’ll check if this array isn’t empty, and if it isn’t we’ll process the contained data:

 if ((materialarray != null) && (materialarray.Length > 0))
 {
     meshmaterials = new Material[materialarray.Length];
     meshtextures = new Texture[materialarray.Length];
 
     for (int i = 0; i < materialarray.Length; i++)
     {
         meshmaterials[i] = materialarray[i].Material3D;
         meshmaterials[i].Ambient = meshmaterials[i].Diffuse;
 
         if ((materialarray[i].TextureFilename != null) && (materialarray[i].TextureFilename != string.Empty))
         {
             meshtextures[i] = TextureLoader.FromFile(device, materialarray[i].TextureFilename);
         }
     }
 }

What this basically does, is extract the texture and material information in separate arrays. For every subset of the mesh, another entry in these arrays will be made. First the material is stored, after which the ambient color is set the same as the diffuse color. Then we check if a texture has to be loaded. If this is the case, the appropriate texture is loaded from a file into the texture array.

Up to this point, we have our mesh and the filled texturearray and materialarray. It’s possible, however, that the mesh loaded from file doesn’t contain any normal data. To solve this, we’ll add normal data as seen in Series 1:

 mesh = mesh.Clone(mesh.Options.Value, CustomVertex.PositionNormalTextured.Format, device);
 mesh.ComputeNormals();

This way, our mesh will interact properly when we switch on the lights. What’s left? We still need to find the radius (=size) of our mesh, which we’ll need when we want to detect collisions between our airplane and our 3D city. To do this, we’ll first extract the vertex data from our mesh to a GraphicsStream object:

 VertexBuffer vertices = mesh.VertexBuffer;
 GraphicsStream stream = vertices.Lock(0, 0, LockFlags.None);
 Vector3 meshcenter;
 meshradius = Geometry.ComputeBoundingSphere(stream, mesh.NumberVertices, mesh.VertexFormat, out meshcenter) * scaling;
 vertices.Unlock();

The last line does all the maths for you: it takes the vertex information and calculates the radius, which is returned. It also returns the center of the mesh, but we don’t need this. The radius is multiplied with our scaling variable.

That’s all that will happen in this method! Before we can load our texture from a file into some variables, we need to declare these variable first. So put these lines at the top of your code:

 private Mesh spacemesh;
 private Material[] spacemeshmaterials;
 private Texture[] spacemeshtextures;
 private float spacemeshradius;
 private float scaling = 0.0005f;

The first mesh will be used to store our airplane. The last variable will be used to decrease the size of our airplane, so it’ll fit in nicely in our environment.

Because later on in this series we’re going to load multiple meshes, we’re going to create another small method called LoadMeshes:

 private void LoadMeshes()
 {
  LoadMesh("xwing.x", ref spacemesh, ref spacemeshmaterials, ref spacemeshtextures, ref spacemeshradius);
 }

You can find this sample mesh here (link). So this is the only method we have to call from our Main method:

 our_directx_form.LoadMeshes();

If you try to run this code, you might get errors like ‘The type or namespace name 'Mesh' could not be found (are you missing a using directive or an assembly reference?)’. This easily solved by adding a reference to Microsoft.DirectX.Direct3DX. Now this code should be runnable, but you won’t see much difference – we haven’t actually instructed DirectX to draw our mesh! So we’re going a add another small method, that draws a certain mesh:

 private void DrawMesh(Mesh mesh, Material[] meshmaterials, Texture[] meshtextures)
 {
  for (int i = 0; i < meshmaterials.Length; i++)
  {
      device.Material = meshmaterials[i];
      device.SetTexture(0, meshtextures[i]);
      mesh.DrawSubset(i);
  }
 }

For a given mesh, this method will loop through all its submeshes. For each submesh, it’ll first set the material and the texture before drawing the part of the mesh. That’s it, now we can call this method from our OnPaint method:

 device.Transform.World = Matrix.Scaling(scaling, scaling, scaling) * Matrix.RotationX((float)Math.PI / 2) * Matrix.Translation(19,5,12);
 DrawMesh(spacemesh, spacemeshmaterials, spacemeshtextures);

First, our mesh is scaled, so it’ll fit in nicely in our game, otherwise it would look incredibly huge. Then, the mesh is rotated 90°, so it will be drawn horizontally. As a last transformation, we position it so it is easy to see with our current camera position.

When you run this code, after a small flash, the airplane will be the only object you’ll see. This is because our World transform stays in the last state, which was set for drawing our airplane. To solve this, we’ll simply reset the World transform matrix immediately before we draw our 3D city:

 device.Transform.World = Matrix.Identity;

The Identity matrix is the unity element of matrix maths. Running this will display both our 3D city as our airplane:




DirectX Tutorial 5 - Meshloading from file

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:
  • Meshes looks strange.
          Thank you for tutorial. My problem is that my mes...
  • my code just load one material!!
          hi dears I made two spheres by milkshape with 2 d...
  • Non-invocable member of method
          can anyone help me from this stuck, When I wro...
  • Exception on debug
          Hello! Everything has worked well til this poin...
  • Using materials
          Hi, I tried to create a few meshes with Blender a...
  • Obtain vertex information from a Mesh
          Hi, I was wondering how it would be possible to...
  • The xwing file
          Hello Riemer..how are u ,hope all's fine Well,...
  • The xwing file
          Hello Riemer..how are u ,hope all's fine Well,...
  • *.x file problems
          Hi, I've been reading through the second serie...
  • *.x file problems
          Hi, I've been reading through the second serie...
  • Putting 3D city into a mesh
          You said that putting the whole city into a mesh w...
  • Mesh Orientation
          A quick question about mesh orientation. I have...
  • custom mesh
          I am trying to use a custom mesh instead of the xw...
  • How you put whole 3D city into one mesh?
           device.DrawUserPrimitives(PrimitiveType.Tr...
  • Did you know tha your Mesh is a RH one?
          I used this xwing.x mesh as a test object and disc...


    I won’t have to draw your attention to the fact that our airplane looks a bit albino-like .. This is simply because we haven’t turned on the lights, which is exactly what we’re going to do next chapter! See you there

     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;
     using D3D = Microsoft.DirectX.Direct3D;
     
     namespace DirectX_Tutorial
     {
         public class WinForm : System.Windows.Forms.Form
         {
             private int[,] int_Floorplan;
             private int WIDTH;
             private int HEIGHT;
             private int differentbuildings = 5;
             private int[] buildingheights = new int[] { 0, 10, 1, 3, 2, 5 };
     
             private System.ComponentModel.Container components = null;
             private D3D.Device device;
             private Texture scenerytexture;
             private Material material;
             private CustomVertex.PositionNormalTextured[] verticesarray;
             ArrayList verticeslist = new ArrayList();
             private Mesh spacemesh;
             private Material[] spacemeshmaterials;
             private Texture[] spacemeshtextures;
             private float spacemeshradius;
             private float scaling = 0.0005f;
     
             public WinForm()
             {
                 InitializeComponent();
                 this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
             }
     
             public void InitializeDevice()
             {
                 PresentParameters presentParams = new PresentParameters();
                 presentParams.Windowed = true;
                 presentParams.SwapEffect = SwapEffect.Discard;
                 presentParams.AutoDepthStencilFormat = DepthFormat.D16;
                 presentParams.EnableAutoDepthStencil = true;
                 device = new D3D.Device(0, D3D.DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
     
                 device.RenderState.Lighting = false;
             }
     
             protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
             {
                 device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.DarkSlateBlue, 1.0f, 0);
                 device.BeginScene();
     
                 device.Transform.World = Matrix.Identity;
                 device.VertexFormat = CustomVertex.PositionNormalTextured.Format;
                 device.SetTexture(0, scenerytexture);
                 device.DrawUserPrimitives(PrimitiveType.TriangleList, verticeslist.Count / 3, verticesarray);
     
                 device.Transform.World = Matrix.Scaling(scaling, scaling, scaling) * Matrix.RotationX((float)Math.PI / 2) * Matrix.Translation(19,5,12);
                 DrawMesh(spacemesh, spacemeshmaterials, spacemeshtextures);
     
                 device.EndScene();
                 device.Present();
                 this.Invalidate();            
             }
     
             private void SetUpCamera()
             {
                 device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, (float)this.Width / (float)this.Height, 0.3f, 500f);
                 device.Transform.View = Matrix.LookAtLH(new Vector3(20, 5, 13), new Vector3(8, 7, 0), new Vector3(0, 0, 1));
             }        
     
             private void LoadTexturesAndMaterials()
             {
                 material = new Material();
     
                 material.Diffuse = Color.White;
                 material.Ambient = Color.White;
     
                 device.Material = material;
     
                 scenerytexture = TextureLoader.FromFile(device, "texturemap.jpg");
             }
     
             private void LoadFloorplan()
             {
                 WIDTH = 20;
                 HEIGHT = 15;
     
                 int_Floorplan = new int[,]
                 {
                     {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                     {1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
                     {1,0,0,1,1,0,0,0,1,1,0,0,1,0,1},
                     {1,0,0,1,1,0,0,0,1,0,0,0,1,0,1},
                     {1,0,0,0,1,1,0,1,1,0,0,0,0,0,1},
                     {1,0,0,0,0,0,0,0,0,0,0,1,0,0,1},
                     {1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
                     {1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
                     {1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
                     {1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
                     {1,0,1,1,0,0,0,1,0,0,0,0,0,0,1},
                     {1,0,1,0,0,0,0,0,0,0,0,0,0,0,1},
                     {1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
                     {1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
                     {1,0,0,0,0,1,0,0,0,0,0,0,0,0,1},
                     {1,0,0,0,0,1,0,0,0,1,0,0,0,0,1},
                     {1,0,1,0,0,0,0,0,0,1,0,0,0,0,1},
                     {1,0,1,1,0,0,0,0,1,1,0,0,0,1,1},
                     {1,0,0,0,0,0,0,0,1,1,0,0,0,1,1},
                     {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                 };        
     
                 Random random = new Random();
                 for (int x = 0; x < WIDTH; x++)
                 {
                     for (int y = 0; y < HEIGHT; y++)
                     {
                         if (int_Floorplan[x, y] == 1)
                         {
                             int_Floorplan[x, y] = random.Next(differentbuildings) + 1;
                         }
                     }
                 }
             }
     
             private void LoadMesh(string filename, ref Mesh mesh, ref Material[] meshmaterials, ref Texture[] meshtextures, ref float meshradius)
             {
                 ExtendedMaterial[] materialarray;
                 mesh = Mesh.FromFile(filename, MeshFlags.Managed, device, out materialarray);
     
                 if ((materialarray != null) && (materialarray.Length > 0))
                 {
                     meshmaterials = new Material[materialarray.Length];
                     meshtextures = new Texture[materialarray.Length];
     
                     for (int i = 0; i < materialarray.Length; i++)
                     {
                         meshmaterials[i] = materialarray[i].Material3D;
                         meshmaterials[i].Ambient = meshmaterials[i].Diffuse;
     
                         if ((materialarray[i].TextureFilename != null) && (materialarray[i].TextureFilename != string.Empty))
                         {
                             meshtextures[i] = TextureLoader.FromFile(device, materialarray[i].TextureFilename);
                         }
                     }                
                 }
     
                 mesh = mesh.Clone(mesh.Options.Value, CustomVertex.PositionNormalTextured.Format, device);
                 mesh.ComputeNormals();
     
                 VertexBuffer vertices = mesh.VertexBuffer;
                 GraphicsStream stream = vertices.Lock(0, 0, LockFlags.None);
                 Vector3 meshcenter;
                 meshradius = Geometry.ComputeBoundingSphere(stream, mesh.NumberVertices, mesh.VertexFormat, out meshcenter) * scaling;
                 vertices.Unlock();
             }
     
             private void LoadMeshes()
             {        
                 LoadMesh("xwing.x", ref spacemesh, ref spacemeshmaterials, ref spacemeshtextures, ref spacemeshradius);
             }
             
             private void DrawMesh(Mesh mesh, Material[] meshmaterials, Texture[] meshtextures)
             {
                 for (int i = 0; i < meshmaterials.Length; i++)
                 {
                     device.Material = meshmaterials[i];
                     device.SetTexture(0, meshtextures[i]);
                     mesh.DrawSubset(i);
                 }
             }
     
             private void VertexDeclaration()
             {
                 float imagesintexture = 1 + differentbuildings * 2;
     
                 for (int x = 0; x < WIDTH; x++)
                 {
                     for (int y = 0; y < HEIGHT; y++)
                     {
                         int currentbuilding = int_Floorplan[x, y];
                         verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y, buildingheights[currentbuilding]), new Vector3(0, 0, 1), (currentbuilding * 2 + 1) / imagesintexture, 1));
                         verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x + 1, y, buildingheights[currentbuilding]), new Vector3(0, 0, 1), currentbuilding * 2 / imagesintexture, 1));
                         verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x + 1, y + 1, buildingheights[currentbuilding]), new Vector3(0, 0, 1), currentbuilding * 2 / imagesintexture, 0));
     
                         verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x + 1, y + 1, buildingheights[currentbuilding]), new Vector3(0, 0, 1), currentbuilding * 2 / imagesintexture, 0));
                         verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y + 1, buildingheights[currentbuilding]), new Vector3(0, 0, 1), (currentbuilding * 2 + 1) / imagesintexture, 0));
                         verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y, buildingheights[currentbuilding]), new Vector3(0, 0, 1), (currentbuilding * 2 + 1) / imagesintexture, 1));
     
                         if (y > 0)
                         {
                             if (int_Floorplan[x, y - 1] != int_Floorplan[x, y])
                             {
                                 if (int_Floorplan[x, y - 1] > 0)
                                 {
                                     currentbuilding = int_Floorplan[x, y - 1];
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y, 0f), new Vector3(0, 1, 0), (currentbuilding * 2 - 1) / imagesintexture, 1));
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x + 1, y, buildingheights[currentbuilding]), new Vector3(0, 1, 0), currentbuilding * 2 / imagesintexture, 0));
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x + 1, y, 0f), new Vector3(0, 1, 0), currentbuilding * 2 / imagesintexture, 1));
     
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x + 1, y, buildingheights[currentbuilding]), new Vector3(0, 1, 0), currentbuilding * 2 / imagesintexture, 0));
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y, 0f), new Vector3(0, 1, 0), (currentbuilding * 2 - 1) / imagesintexture, 1));
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y, buildingheights[currentbuilding]), new Vector3(0, 1, 0), (currentbuilding * 2 - 1) / imagesintexture, 0));
     
                                 }
                                 if (int_Floorplan[x, y] > 0)
                                 {
                                     currentbuilding = int_Floorplan[x, y];
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y, 0f), new Vector3(0, -1, 0), currentbuilding * 2 / imagesintexture, 1));
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x + 1, y, 0f), new Vector3(0, -1, 0), (currentbuilding * 2 - 1) / imagesintexture, 1));
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x + 1, y, buildingheights[currentbuilding]), new Vector3(0, -1, 0), (currentbuilding * 2 - 1) / imagesintexture, 0));
     
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y, 0f), new Vector3(0, -1, 0), currentbuilding * 2 / imagesintexture, 1));
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x + 1, y, buildingheights[currentbuilding]), new Vector3(0, -1, 0), (currentbuilding * 2 - 1) / imagesintexture, 0));
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y, buildingheights[currentbuilding]), new Vector3(0, -1, 0), currentbuilding * 2 / imagesintexture, 0));
                                 }
     
                             }
                         }
     
                         if (x > 0)
                         {
                             if (int_Floorplan[x - 1, y] != int_Floorplan[x, y])
                             {
                                 if (int_Floorplan[x - 1, y] > 0)
                                 {
                                     currentbuilding = int_Floorplan[x - 1, y];
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y, 0f), new Vector3(1, 0, 0), currentbuilding * 2 / imagesintexture, 1));
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y + 1, 0f), new Vector3(1, 0, 0), (currentbuilding * 2 - 1) / imagesintexture, 1));
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y + 1, buildingheights[currentbuilding]), new Vector3(1, 0, 0), (currentbuilding * 2 - 1) / imagesintexture, 0));
     
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y + 1, buildingheights[currentbuilding]), new Vector3(1, 0, 0), (currentbuilding * 2 - 1) / imagesintexture, 0));
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y, buildingheights[currentbuilding]), new Vector3(1, 0, 0), currentbuilding * 2 / imagesintexture, 0));
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y, 0f), new Vector3(1, 0, 0), currentbuilding * 2 / imagesintexture, 1));
                                 }
                                 if (int_Floorplan[x, y] > 0)
                                 {
                                     currentbuilding = int_Floorplan[x, y];
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y, 0f), new Vector3(-1, 0, 0), (currentbuilding * 2 - 1) / imagesintexture, 1));
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y, buildingheights[currentbuilding]), new Vector3(-1, 0, 0), (currentbuilding * 2 - 1) / imagesintexture, 0));
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y + 1, 0f), new Vector3(-1, 0, 0), currentbuilding * 2 / imagesintexture, 1));
     
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y, buildingheights[currentbuilding]), new Vector3(-1, 0, 0), (currentbuilding * 2 - 1) / imagesintexture, 0));
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y + 1, buildingheights[currentbuilding]), new Vector3(-1, 0, 0), currentbuilding * 2 / imagesintexture, 0));
                                     verticeslist.Add(new CustomVertex.PositionNormalTextured(new Vector3(x, y + 1, 0f), new Vector3(-1, 0, 0), currentbuilding * 2 / imagesintexture, 1));
                                 }
                             }
                         }
                     }
                 }
                 verticesarray = (CustomVertex.PositionNormalTextured[])verticeslist.ToArray(typeof(CustomVertex.PositionNormalTextured));
             }
     
             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 = "Riemer's DirectX Tutorial using C# -- Season 2";
             }
     
             static void Main()
             {
                 using (WinForm our_directx_form = new WinForm())
                 {
                     our_directx_form.InitializeDevice();
                     our_directx_form.SetUpCamera();
                     our_directx_form.LoadFloorplan();
                     our_directx_form.VertexDeclaration();
                     our_directx_form.LoadTexturesAndMaterials();
                     our_directx_form.LoadMeshes();
                     Application.Run(our_directx_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)
    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)
    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!