Category Archives: XNA

XNA Index Buffers on Laptops

I have been working through The Hazy Mind XNA tutorials at http://www.thehazymind.com/XNAEngine.htm.

The computer I have been using for development is my old laptop that has a Intel 915 GM. This card has integrated pixel shading, but relies on the CPU for vertex shading. It also has some other issues, but I won’t go into those now.

As I went through the tutorials, I was having issues rendering the textured quads that are the first object made and rendered. These quads are also used to create the skybox, so getting them working was required to continue developing through these tutorials.

These two pictures show the issues I was having. The first picture shows a single triangle not rendering correctly, and the second shows two triangles not rendering.

Int Render Error 1

Int Render Error 2

After quite a few tries, I finally discovered what the problem was. In the tutorial code, the Index Buffer is created using:


int[] inds = { 0, 1, 2, 1, 3, 2 };

myIndices = new IndexBuffer(myDevice, typeof(int), 6, ResourceUsage.WriteOnly, ResourceManagementMode.Automatic);

myIndices.SetData(inds, 0, 6, SetDataOptions.None);

In this, each of the indicies is represented by an integer. For some reason, using ints causes the rendering errors. By looking at other tutorials, I found that many of them used shorts instead (A short is just an integer that uses less memory and stores a smaller range of numbers).

To fix the errors, all I had to do was change the code to:


short[] inds = { 0, 1, 2, 1, 3, 2 };

myIndices = new IndexBuffer(myDevice, typeof(short), 6, ResourceUsage.WriteOnly, ResourceManagementMode.Automatic);

myIndices.SetData(inds, 0, 6, SetDataOptions.None);

Here is the final result. You can see that the rendering problems are gone.

Short Render