Engineering Two Assignment 3

Assignment 3 Download!

So this assignment was to change our previous single colored triangle into a single colored rectangle. If we only use triangles, my original thought was that we had to double the number of vertices used. Then there’s also triangle strips, which can get complicated, because you just add one more vertex per triangle added. The GPU assumes that the last two points for the previous triangle are the first two for the next one. This can make things kind of complicated without a tool to generate the triangle strip for you. However, the tactic we used was somewhere in between. So we used an index list along with the vertex list.


The vertex list holds all of the points on the rectangle, so in the picture above, it holds each corner in the list. Then the index list holds the order for the points. For the first triangle, the index list is 0, 1, 2. Then the second triangle is 1, 3, 2. This is a neat way to do it because you only have to store each vertex once, and only lose a little space for all the indices, which isn’t too bad at all. It’s also worth noting that DirectX makes the edges of the screen go from -1 to 1. So although by coordinates, it should be a square, due to the resolution of the window, it appears stretched into a rectangle.


The picture above is just like the last assignment, but this time with more triangles! In the PreVS window, you can see the VTX, which is the vertices used, so the first three are for the first triangle. 3-5 is for the second triangle. In the next column, in the IDX, you can see the index list that I mentioned in the prior paragraph and the point that is associated with it. Nifty.

The next part of the assignment was to switch the hardcoding of which shaders to use into a more dynamic, reader-friendly approach. We created materials, which describe how things look, and essentially which shaders are used for an object. Using our previous LUA knowledge, we can convert a material into a basic LUA table that can be read in. I made a material manager class, which can store all the materials loaded in to the game. This way, you can load them all up during load time, and then just call the ones you need when you need them. A material is just a vertex shader and a fragment(pixel) shader. Taking this a step further, when we add in meshes that hold the triangle lists needed to draw an object, we could hold the mesh and the material in the object and call draw, and it will do all the work of making sure it’s using the right materials on the right mesh. My LUA file looks like this:

vertexShaderPath = “data/vertexShader.hlsl”,
fragmentShaderPath = “data/fragmentShader.hlsl”,


Time Spent:
Adding index buffer and triangle list: 1 Hour
Switching materials to a class: 1 Hour
Adding in LUA to read materials: 1 Hour
Writeup: 30 Minutes

Leave a Reply