Lines

Introduction

Drawing Lines

Lesson Downloads

Introduction

The basic primitive types are points, lines and triangles. With points taken care of in the previous lesson, we're moving on to lines. We're still using Screen Space coordinates and we're going to use the same data sets as we did in the Points lesson. When you see how few changes we had to make for this lesson you'll see how similar the different primitives are.

Drawing Lines

As I mentioned above, very few changes were required to convert the Points lesson to use lines. Additionally, this lesson will show both Line Lists and Line Strips. The random data set will be used to render the Line Lists and the sine data will be used on the Line Strips. Here's the Draw call for the random data.

   m_device.DrawUserPrimitives(D3D.PrimitiveType.LineList, //The type of primitive we're rendering

                               ClientSize.Width / 2,       //The number of primitives we're rendering

                               m_random_data);             //The data to render

   '           D3D.PrimitiveType.LineList:  The type of primitive we're rendering

   '                   ClientSize.Width\2:  The number of primitives we're rendering

   '                          _randomData:  The data to render

   _device.DrawUserPrimitives(D3D.PrimitiveType.LineList, ClientSize.Width \ 2, _randomData)

Our PrimitiveType is PrimitiveType.LineList. Though we are using the same number of vertices as the Points sample, our PrimitiveCount is different. Each line takes up 2 vertices, so the number of primitives is equal to half the number of vertices.

Line Strips are connected lines. The first 2 vertices form the first line and then each additional line adds a line using the previous vertex. By drawing our sine data with a line strip, we get a smooth continuous wave.

   m_device.DrawUserPrimitives(D3D.PrimitiveType.LineStrip, //The type of primitive we're rendering

                               ClientSize.Width - 1,        //The number of primitives we're rendering

                               m_sine_data);                //The data to render

   '          D3D.PrimitiveType.LineStrip:  The type of primitive we're rendering

   '                   ClientSize.Width-1:  The number of primitives we're rendering

   '                            _sineData:  The data to render

   _device.DrawUserPrimitives(D3D.PrimitiveType.LineStrip, ClientSize.Width - 1, _sineData)

The change to the PrimitiveType is obvious. The only other thing that's different is the PrimitiveCount. Each additional vertex adds one line strip, but the first line is made up of 2 vertices. So our PrimitiveCount is 1 less than the total number of vertices.

Lesson Downloads

Back