1.4 Defining and Loading Vertices

Once the matrix has been loaded into the RSP, the next step is to load the vertices in order to define the model. As mentioned previously, when the vertices are loaded into the vertex buffer the coordinates are transformed according to the set matrix, so you need to remember to load the matrix before you load the vertices.

Next we will cover defining vertices. Vertex information is stored in the Vtx union. The meanings of some of the elements in the Vtx union change when coloring with vertex color, and when performing lighting processes. This will be explained in detail in the next chapter when we talk about shading.

List 1-3

static Vtx  square_vtx[] = {
  {-10, -10, 0, 0, 0, 0, 255,   0,   0, 255},
  { 10, -10, 0, 0, 0, 0,   0, 255,   0, 255},
  { 10,  10, 0, 0, 0, 0,   0,   0, 255, 255},
  {-10,  10, 0, 0, 0, 0, 255, 255, 255, 255},
};

In this example the Vtx union is an array, so an explanation will be done by focusing on single elements in the array.

The first three elements in the Vtx structure are short type integer values that store the x, y, z coordinates of the vertex. This example defines a vertex with the coordinate values (-10, -10, 0).

The next element is not being used at the present time, so will not be explained here. The next two elements following this are parameters relating to texture mapping, and will be covered in Chapter 3 when we talk about the handling of textures.

The last four elements indicate the color of the vertex in the order of R, G, B, A. See Chapter 6 for details about A, the alpha value. As will be explained in the next chapter, in the case of lighting you need to store the normal vector components here rather than the RGB values.

Once you have defined vertices this way, load them into the RSP's vertex buffer using the gSPVertex command.

List 1-4

  /* Load the model's vertices  */
  gSPVertex(glistp++, square_vtx, 4, 0);

The arguments in gSPVertex specify the pointer to the Vtx union array, followed by the number of vertices to be loaded, and the index at the start of the load destination. Both the number of vertices that can be loaded at the same time and the range of valid index values will differ, depending on the microcode that is being used. (The valid range of index values also depends on the size of the vertex buffer.)

Number of vertices that can be loaded at the same time:
F3DEX2
F3DEX2.NoN
F3DLX2
F3DLX2.NoN
L3DEX2
1-32
F3DEX2.Rej
F3DLX2.Rej
1-64

Specifiable starting index:
F3DEX2
F3DEX2.NoN
F3DLX2
F3DLX2.NoN
L3DEX2
0-31
F3DEX2.Rej
F3DLX2.Rej
0-63