next up previous contents index
Next: 2.6.2 Polygon Edges Up: 2.6 Begin/End Paradigm Previous: 2.6 Begin/End Paradigm

2.6.1 Begin and End Objects

 

Begin  and End  require one state variable with eleven values: one value for each of the ten possible Begin / End  objects, and one other value indicating that no Begin / End  object is being processed. The two relevant commands are

void Begin ( enum mode ) ;
void End ( void ) ;

There is no limit on the number of vertices that may be specified between a Begin  and an End .

Points. A series of individual points may be specified by calling Begin  with an argument value of POINTS. No special state need be kept between Begin  and End  in this case, since each point is independent of previous and following points.

Line Strips. A series of one or more connected line segments is specified by enclosing a series of two or more endpoints within a Begin / End  pair when Begin  is called with LINE_STRIP. In this case, the first vertex specifies the first segment's start point while the second vertex specifies the first segment's endpoint and the second segment's start point. In general, the ith vertex (for i > 1) specifies the beginning of the ith segment and the end of the i-1st. The last vertex specifies the end of the last segment. If only one vertex is specified between the Begin / End  pair, then no primitive is generated.

The required state consists of the processed vertex produced from the last vertex that was sent (so that a line segment can be generated from it to the current vertex), and a boolean flag indicating if the current vertex is the first vertex.

Line Loops. Line loops, specified with the LINE_LOOP argument value to Begin , are the same as line strips except that a final segment is added from the final specified vertex to the first vertex. The additional state consists of the processed first vertex.

Separate Lines. Individual line segments, each specified by a pair of vertices, are generated by surrounding vertex pairs with Begin  and End  when the value of the argument to Begin  is LINES. In this case, the first two vertices between a Begin  and End  pair define the first segment, with subsequent pairs of vertices each defining one more segment. If the number of specified vertices is odd, then the last one is ignored. The state required is the same as for lines but it is used differently: a vertex holding the first vertex of the current segment, and a boolean flag indicating whether the current vertex is odd or even (a segment start or end).

Polygons. A polygon is described by specifying its boundary as a series of line segments. When Begin  is called with POLYGON, the bounding line segments are specified in the same way as line loops. Depending on the current state of the GL, a polygon may be rendered in one of several ways such as outlining its border or filling its interior. A polygon described with fewer than three vertices does not generate a primitive.

Only convex polygons are guaranteed to be drawn correctly by the GL. If a specified polygon is nonconvex when projected onto the window, then the rendered polygon need only lie within the convex hull of the projected vertices defining its boundary.

The state required to support polygons consists of at least two processed vertices (more than two are never required, although an implementation may use more); this is because a convex polygon can be rasterized as its vertices arrive, before all of them have been specified. The order of the vertices is significant in lighting and polygon rasterization (see sections 2.13.1 and 3.5.1).

Triangle strips. A triangle strip is a series of triangles connected along shared edges. A triangle strip is specified by giving a series of defining vertices between a Begin / End  pair when Begin  is called with TRIANGLE_STRIP. In this case, the first three vertices define the first triangle (and their order is significant, just as for polygons). Each subsequent vertex defines a new triangle using that point along with two vertices from the previous triangle. A Begin / End  pair enclosing fewer than three vertices, when TRIANGLE_STRIP has been supplied to Begin , produces no primitive. See Figure 2.4.

  
Figure 2.4: (a) A triangle strip. (b) A triangle fan. (c) Independent triangles. The numbers give the sequencing of the vertices between Begin  and End . Note that in (a) and (b) triangle edge ordering is determined by the first triangle, while in (c) the order of each triangle's edges is independent of the other triangles.

The state required to support triangle strips consists of a flag indicating if the first triangle has been completed, two stored processed vertices, (called vertex A and vertex B), and a one bit pointer indicating which stored vertex will be replaced with the next vertex. After a Begin  ( TRIANGLE_STRIP), the pointer is initialized to point to vertex A. Each vertex sent between a Begin / End  pair toggles the pointer. Therefore, the first vertex is stored as vertex A, the second stored as vertex B, the third stored as vertex A, and so on. Any vertex after the second one sent forms a triangle from vertex A, vertex B, and the current vertex (in that order).

Triangle fans. A triangle fan is the same as a triangle strip with one exception: each vertex after the first always replaces vertex B of the two stored vertices. The vertices of a triangle fan are enclosed between Begin  and End  when the value of the argument to Begin  is TRIANGLE_FAN.

Separate Triangles. Separate triangles are specified by placing vertices between Begin  and End  when the value of the argument to Begin  is TRIANGLES. In this case, The 3i+1st, 3i+2nd, and 3i+3rd vertices (in that order) determine a triangle for each , where there are 3n+k vertices between the Begin  and End . k is either 0, 1, or 2; if k is not zero, the final k vertices are ignored. For each triangle, vertex A is vertex 3i and vertex B is vertex 3i+1. Otherwise, separate triangles are the same as a triangle strip.

The rules given for polygons also apply to each triangle generated from a triangle strip, triangle fan or from separate triangles.

Quadrilateral (quad) strips. Quad strips generate a series of edge-sharing quadrilaterals from vertices appearing between Begin  and End , when Begin  is called with QUAD_STRIP. If the m vertices between the Begin  and End  are , where is the jth specified vertex, then quad i has vertices (in order) , , , and with . The state required is thus three processed vertices, to store the last two vertices of the previous quad along with the third vertex (the first new vertex) of the current quad, a flag to indicate when the first quad has been completed, and a one-bit counter to count members of a vertex pair. See Figure 2.5.

  
Figure 2.5: (a) A quad strip. (b) Independent quads. The numbers give the sequencing of the vertices between Begin  and End .

A quad strip with fewer than four vertices generates no primitive. If the number of vertices specified for a quadrilateral strip between Begin  and End  is odd, the final vertex is ignored.

Separate Quadrilaterals Separate quads are just like quad strips except that each group of four vertices, the 4j+1st, the 4j+2nd, the 4j+3rd, and the 4j+4th, generate a single quad, for . The total number of vertices between Begin  and End  is 4n+k, where ; if k is not zero, the final k vertices are ignored. Separate quads are generated by calling Begin  with the argument value QUADS.

The rules given for polygons also apply to each quad generated in a quad strip or from separate quads.



next up previous contents index
Next: 2.6.2 Polygon Edges Up: 2.6 Begin/End Paradigm Previous: 2.6 Begin/End Paradigm



David Blythe
Sat Mar 29 02:23:21 PST 1997