Fixing bad code
Posted: Fri May 14, 2010 6:03 am
So I spent about 2 days going through working with 3D primitives in XNA using BasicEffect which is their pre-defined shader 1.1 class (and I've only scratched the surface - haven't even really gotten into buffers, lighting, etc.) and trying to get a basic triangle with colored points to draw (red, green, and blue). I wound up spending several hours (and a couple hours flipping to other things since I wasn't getting anywhere) going through my code to figure out why my implementation didn't work when the tutorial example that I was following did (they were almost exactly the same except that I made a separate class for mine since I intend on doing some work with primitives in a project that I'm working on).
Turns out that it wasn't anything complex, it was just the way I created the vertices:
I was tired at the time of originally creating it and created (and overwrote) the same vertice 3 times... and for that I spent hours manually debugging my code looking for errors that wouldn't have been picked up by the compiler. Any tips for catching errors like this... or stories you'd like to share about similar experiences?
Turns out that it wasn't anything complex, it was just the way I created the vertices:
Code: Select all
vertices = new VertexPositionColor[3];
vertices[0] = new VertexPositionColor(new Vector3(0, 1, 0), Color.Red);
vertices[0] = new VertexPositionColor(new Vector3(0.5f, 0, 0), Color.Green);
vertices[0] = new VertexPositionColor(new Vector3(-0.5f, 0, 0), Color.Blue);