Game Development Reference
In-Depth Information
Finally, it's time for the index stream to be created. Again, as with 2D rendering, this
is just an array of uint16 values which indicate the order in which elements of the
streams should be accessed. Here's the code:
const uint32 lIndexCount = 34;
uint16* i = new uint16[lIndexCount];
// Front face (red)
i[0] = 0; i[1] = 1; i[2] = 2; i[3] = 3;
// Degenerate
i[4] = 3; i[5] = 7;
// Right face (yellow)
i[6] = 7; i[7] = 6; i[8] = 5; i[9] = 4;
// Degenerate
i[10] = 4; i[11] = 9;
// Back face (green)
i[12] = 9; i[13] = 11; i[14] = 8; i[15] = 10;
// Degenerate
i[16] = 10; i[17] = 12;
// Left face (blue)
i[18] = 12; i[19] = 13; i[20] = 14; i[21] = 15;
// Degenerate
i[22] = 15; i[23] = 16;
// Bottom face (cyan)
i[24] = 16; i[25] = 17; i[26] = 18; i[27] = 19;
// Degenerate
i[28] = 19; i[29] = 23;
// Top face (orange)
i[30] = 23; i[31] = 21; i[32] = 22; i[33] = 20;
Note than the first four values in the stream define the first full face of the cube. The
next two values form a degenerate triangle that allows us to link the first face to the
second face without actually rendering anything. As we saw earlier in this chapter,
the easiest way to link two triangle strips is to repeat the last index of the first strip
and start the next strip with two copies of its first index. This pattern continues until
we've drawn the last face of the cube.
The order in which the vertices are specified is the most important consideration, as
we must ensure we get this correct for the culling mode we'll be using. For back-face
culling (so faces that are away from the camera are not rendered) we need the vertex
order to be in anti-clockwise order for the first triangle specified.
 
Search WWH ::




Custom Search