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

Moving From DirectX9 to XNA

I’ve been working the last week on getting started with XNA and how to port AquariusSim over to it. Learning XNA has been easier than I expected it to be since I had already written a lot of code in DirectX9.

Microsoft did a good job with most of XNA, but there are a few things that I think will really frustrate new developers. Getting started has been improved a lot. It now only takes a few lines to set up a device and render a blank screen. That was one of the things that took me the longest when I was starting to learn DirectX. Most of the complexity of setting up the device has been hidden, which makes it a lot simpler. It might end up making some advanced features harder to implement, but I am not sure because I never used any of them.

Switching to fullscreen is also a lot easier. When I was working on the first version of AquariusSim I remember spending days working on getting that to work, but its now just a few lines of code.

The one thing I like the least about XNA is the removal of the Fixed Pipeline. The Fixed Pipeline in DirectX allowed you to render objects using simple Lighting Objects and not have to worry about learning another programming language to implement shaders. XNA has removed this functionality and requires shaders to be written for everything. This means that the programmer has to either learn a completely new langauge, or they have to just use other people’s shaders without understanding how to change them. This could end up being a serious block to new game developers.

Overall, I think Microsoft made some really good decisions for XNA and I think that for someone experienced with 3D graphics it will be an easy switch. But as before, there are some serious roadblocks that could make aspiring game developers give up before they get very far into it.

Now, back to working on this port. Hopefully I should have some screenshots up soon and maybe even some code examples of what I am doing.