Setting Up the Vertex Buffer


As I touched on briefly in the Converting Model Coordinates to the View Frame section earlier, the point data for the objects that will be rendered get packed into a vertex buffer. The DrawPrimitive method called in the rendering phase will employ the vertex buffer to render using this information. The type of primitive specified must match the way in which the vertices are placed in the buffer to get the desired results.

Five basic primitive types can be used for rendering: point, line, triangle list, triangle strip, and triangle fan. The point primitive is used for rendering individual pixels onto the screen, such as when you want to depict stars in a night sky or in outer space. Another more prevalent use is for rendering point particles in a particle system. (Particle systems will be covered as part of Chapter 4.) Each vertex in the vertex buffer for points is the three-dimensional position of the point as well as the color information for that point. The number of primitives of this type will match the number of vertices in the buffer.

The second primitive, line, is used for drawing single-pixel-wide lines between two points in three-dimensional space. This is probably one of the least used primitive types. Its only utility is to render heads-up display information as part of an overlay. The primitive actually comes in two types: LineList and LineStrip . This list version declares that for every two points in the vertex buffer there will be a line drawn. Note that there must be an even number of points in the vertex buffer if we are rendering a line list. The strip version renders one multisegment line using the points in the buffer.

The remaining primitives are the ones that see the most usage in 3D games . These render triangles, with specific relationships between the triangles. The first and most common is the triangle list. For each set of three vertices in the buffer, one triangle will be rendered. This method requires the least amount of setup of the three triangle types. If the triangles of the object being rendered are adjacent to one another, we can take advantage of this fact and the fact that the adjacent polygons share common vertices.

The triangle strip primitive is used if the last two vertices of each triangle are also part of the next triangle in the buffer. This provides a roughly 66 percent performance gain over the triangle list since only about a third as many vertices need to be transformed to screen coordinates. In order to use this primitive, we must model the object in this manner and make sure that the vertex buffer is packed properly. Triangle strips are most commonly used when rendering a rectangular region. Figure 3 “4 gives an example of a triangle strip.

click to expand
Figure 3 “4: Triangle strip

The last primitive is the triangle fan. The fan has the same benefits as the strip, but serves a slightly different purpose. In a triangle fan, the first vertex in the buffer is common to all triangles in the fan. The last vertex in each triangle is also common with the next triangle. Figure 3 “5 gives an example of a triangle fan.

click to expand
Figure 3 “5: Triangle fan



Introduction to 3D Game Engine Design Using DirectX 9 and C#
Introduction to 3D Game Engine Design Using DirectX 9 and C#
ISBN: 1590590813
EAN: 2147483647
Year: 2005
Pages: 98

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net