Triangle Lists

A triangle list is a list of isolated triangles. They may or may not be near each other. A triangle list must have at least three vertices. The total number of vertices must be divisible by three.

Use triangle lists when you want to create an object that is composed of disjoint pieces. For instance, one way to create a force field wall in a 3-D game is to specify a large list of small, unconnected triangles. Then apply a material or texture to the triangle list that emits light. Each triangle in the wall appears to glow. The scene behind the wall becomes partially visible through the gaps between the triangles, as players might expect when looking at a force field.

Triangle lists are also useful for creating primitives that have sharp edges and are shaded with Gouraud shading. See Face and Vertex Normal Vectors.

Create a triangle list by filling an array of vertices, as in the following code fragment:

const DWORD TOTAL_VERTS=6;
D3DVERTEX lpVerts[TOTAL_VERTS];
 
lpVerts[0] = D3DVERTEX(D3DVECTOR(-5,-5,0),D3DVECTOR(0,0,-1),0,0);
lpVerts[1] = D3DVERTEX(D3DVECTOR(0,5,0),D3DVECTOR(0,0,-1),0,0);
lpVerts[2] = D3DVERTEX(D3DVECTOR(5,-5,0),D3DVECTOR(0,0,-1),0,0);
lpVerts[3] = D3DVERTEX(D3DVECTOR(10,5,0),D3DVECTOR(0,0,-1),0,0);
lpVerts[4] = D3DVERTEX(D3DVECTOR(15,-5,0),D3DVECTOR(0,0,-1),0,0);
lpVerts[5] = D3DVERTEX(D3DVECTOR(20,5,0),D3DVECTOR(0,0,-1),0,0);
 

Render a triangle list using the IDirect3DDevice3::DrawPrimitive method. The following code fragment illustrates the use of IDirect3DDevice3::DrawPrimitive for drawing the triangle list in the preceding example. Remember that all calls to IDirect3DDevice3::DrawPrimitive must occur between IDirect3DDevice3::BeginScene and IDirect3DDevice3::EndScene.

HRESULT hResult;
// This code fragment assumes that lpDirect3DDevice3 is a valid 
// pointer to an IDirect3DDevice3 interface.
hResult = 
    lpDirect3DDevice3 ->DrawPrimitive(D3DPT_TRIANGLELIST,
                                      D3DFVF_VERTEX,
                                      lpVerts,
                                      TOTAL_VERTS,
                                      D3DDP_WAIT); 
 

The following illustration depicts the resulting triangles.