DirectX SDK

Line Strips

A line strip is a primitive that is composed of connected line segments. Your application can use line strips for creating polygons that are not closed. A closed polygon is a polygon whose last vertex is connected to its first vertex by a line segment. If your application makes polygons based on line strips, the vertices are not guaranteed to be coplanar. You create a line strip by filling an array of vertices.

[C++]

The following code fragment illustrates this process using C++:

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 the line list using the IDirect3DDevice7::DrawPrimitive method. The following code fragment illustrates the use of IDirect3DDevice7::DrawPrimitive for drawing the line strip in the preceding example. Remember that all calls to IDirect3DDevice7::DrawPrimitive must occur between IDirect3DDevice7::BeginScene and IDirect3DDevice7::EndScene.

HRESULT hResult;
// This code fragment assumes that lpDirect3DDevice is a valid 
// pointer to an IDirect3DDevice7 interface.
hResult = 
    lpDirect3DDevice->DrawPrimitive(D3DPT_LINESTRIP,
                                      D3DFVF_VERTEX,
                                      lpVerts,
                                      TOTAL_VERTS,
                                      D3DDP_WAIT); 
[Visual Basic]

This code fragment illustrates this process using Visual Basic.

' This code fragment assumes that dx is a valid reference
' to a DirectX7 object.
On Local Error Resume Next
Const TOTAL_VERTS As Integer = 6
Dim Verts(TOTAL_VERTS) As D3DVERTEX
 
Verts(0) = dx.CreateD3DVertex(-5, -5, 0, 0, 0, -1, 0, 0)
Verts(1) = dx.CreateD3DVertex(0, 5, 0, 0, 0, -1, 0, 0)
Verts(2) = dx.CreateD3DVertex(5, -5, 0, 0, 0, -1, 0, 0)
Verts(3) = dx.CreateD3DVertex(10, 5, 0, 0, 0, -1, 0, 0)
Verts(4) = dx.CreateD3DVertex(15, -5, 0, 0, 0, -1, 0, 0)
Verts(5) = dx.CreateD3DVertex(20, 5, 0, 0, 0, -1, 0, 0)

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

' This code fragment assumes that d3ddev is a valid
' reference to an Direct3DDevice7 object.
Call d3ddev.DrawPrimitive(D3DPT_LINESTRIP, _ 
                          D3DFVF_VERTEX, _ 
                          Verts(0), _ 
                          TOTAL_VERTS, _ 
                          D3DDP_WAIT)
 
If Err.Number <> DD_OK Then
    ' Code to handle error goes here.
End If

The following illustration shows the line strip that the previous code produces.