OpenGL Polygon Fill area function (top)The OpenGL process that describes the fill polygon is similar to the description point and polyline, with one exception. The function Glvertex is used to entera vertex coordinate of a polygon, and a complete polygon is described by a set of vertices from Glbegin to glend. But there is anothera function can be used to display a rectangle with a completely different format.
The polygon interior is displayed as monochrome by default, and its color is determined by the current color setting. As an option (described in the following section),you can fill a polygon with a pattern and display the edges of the polygon as the boundary of the inner fill. Specify polygon fill area in function Glbeginvariable can use 6 different symbolic constants. These 6 basic constants can be used to display a single filled polygon, a group of disconnectedFilled polygons or a set of connected fill polygons.
the fill area in OpenGL must be specified as a convex polygon. Therefore, a filled polygon's vertex set contains at least three topPoint, where there are no intersecting edges, and all inner angles of the polygon are less than 180 degrees. A single polygon fill area is described with only one vertex set, with its internalthe hole shown in Figure 3.54 cannot be included. Such a graph can be described by two overlapping polygons.
Each polygon we describe has two faces: a back face and a forward face. In OpenGL, you can set each face individuallyfill Color and other properties, and require a back/forward flag in two-and three-dimensional observer subroutines. Therefore, the polygon is pressed from the outsidedescription of the counter-clockwise direction when observing it. This identifies the forward face of the polygon.
because the graphical display often contains a rectangular fill area, OpenGL provides a special rectangular function,describes vertices directly in the XY plane. In some implementations of OpenGL, the following function is more efficient than the fill area described by G1vertex:
glrect* (x1, y1, x2, y2);
a corner of the rectangle is at the coordinate position (X1,Y1), and its relative corner is at the coordinate position (X2,Y2). Suffix of glrectThe code indicates the coordinate data type and whether the coordinate is represented by an array element. These encodings are I (integer), s (short integer), f (floating point, D (double-long floating-point numbers) and V (vectors). The edges of the rectangle are parallel to the XY axis. As an example, the following statement willThe squares given in figure 3.55 are justified:
GLRECTI (200, 100, 50, 250);
If you place the coordinate values in an array, the following statements can be used to generate the same squares:
int Vertex1 [] = {$, 1000};int vertex2 [] = {250};GLRECTV (vertex1, VERTEX2);
when a rectangle is generated using the function glrect, the edges of the polygon are formed by the vertex sequence (x1,y1), (X2,y1), (X2,y2), (x1,y2) ,Back to the first vertex (x1,yl). In this example, we generate a set of vertices in the clockwise order. In many two-dimensional applications, the formerIt is not important to determine the faces and the back faces. But if you really want to assign different attributes to the forward and back faces of the rectangle, you shouldthe order of two vertices in this example is reversed to get the vertex order counterclockwise. The 4th chapter will discuss another way to reverse the forward
the method that the face and the back face describe.
each of the other six OpenGL polygon-filled entities uses symbolic constants from the Glbegin function and a set of GlvertexThe command description. Use the OpenGL entity constants Gl_polygon to display a single polygon such as Figure 3.56 (a). In this example, we assume that there are six vertices, labeled P1 to P6, that describe a two-D polygon vertex position in a counterclockwise order. Each point usesan array (x, y) coordinate value is represented.
Glbenin (Gl_polygon); Glvertex2iv (p1); Glvertex2iv (p2); Glvertex2iv (p3); Glvertex2iv (p4); Glvertex2iv (p5); Glvertex2iv (P6); Glend ();
the vertex set of a polygon contains at least three vertices, otherwise nothing is displayed.
If you change the order of the vertex sets in the previous example and change the entity constants to Gl_triangles, you get the two separate triangular fill areas shown in Figure 3.56 (b).
Glbenin (Gl_triangles); Glvertex2iv (p1); Glvertex2iv (p2); Glvertex2iv (p3); Glvertex2iv (p4); Glvertex2iv (p5); Glvertex2iv (P6); Glend ();
At this point, the first three coordinate points define the vertices of a triangle, and then three points define the next triangle, and so on. For each triangle fill area, we specify the vertex position in the counterclockwise order. Unless some vertices are reused, the entity constants display only the unconnected triangles. If the number of vertices is less than 3, nothing is displayed. If the specified number of vertices is not a multiple of 3, the last or two vertices are not used.
Change the vertex set order again and change the entity constant to Gl_triangle_strip, which shows a set of connected triangles as shown in Figure 3.56 (c).
Glbenin (Gl_triangle_strip); Glvertex2iv (p1); Glvertex2iv (p2); Glvertex2iv (P6); Glvertex2iv (p3); Glvertex2iv (p5); Glvertex2iv (p4); Glend ();
It is assumed that there is no duplicate coordinate position in the collection of n vertices to obtain a band of N-2 triangles. It is clear that there must be N >= 3, otherwise nothing is displayed. In this example,n=6, get 4 triangles。 Each successive triangle shares an edge of the triangle defined earlier, so the setting of the vertex order must guarantee the consistency of the display. A triangle is defined by adding a vertex to the first two vertices.Therefore, the first three vertices must be listed in a counter-clockwise order from the Front (outer) view of the triangle surface. Then, the three vertices in the vertex table for the other three triangles are arranged in a clockwise order. This is done by sequentially N=1,N=2....N = N-2 processing the position n of the vertex set, and by whether N is an odd or even number to determine the corresponding three-vertex set order. If n is odd, the polygon list order of the triangle vertices is N, n+1, n+2. If n is an even number, the triangle vertex order is. N+l, N, n+2。 In the previous example, the first triangle (n=1) has the vertex order (P1, p2, p6). The second triangle (n = 2) has the vertex order (P6, P2, p3). The third triangle (n=3) is (P6, P3, p5). The vertex order of the fourth triangle (n=4) in a polygon table is (P5, P3, p4).
Another way to generate a set of connected triangles is to use the "fan" method shown in Figure 3.56 (d), where one vertex is shared by all triangles. Such a setting can be obtained using primitive constants Gl_triangle_fan and the original order of six vertices:
Glbenin (Gl_triangle_fan); Glvertex2iv (p1); Glvertex2iv (p2); Glvertex2iv (p3); Glvertex2iv (p4); Glvertex2iv (p5); Glvertex2iv (P6); Glend ();
n vertices get N-2 triangles, no vertices need to be reused, but at least three vertices must be listed . In addition, the vertex order must be appropriately described in order to correctly define the forward and back faces of each triangle. The first listed vertex (pl at this time) is the vertex shared by each triangle in the pie sector. If you press n=1,n=2,..., n=n-2 to calculate the polygon and coordinate position, the nth triangle in the polygon table has a vertex order of 1, n+1, n+2. Therefore, the triangle 1 is defined by the vertex set (P1,P2,P3), the vertex order of the Triangle 2 is (P1, P3, p4), the vertex order of the Triangle 3 is (P1,P4,P5), and the vertex set of the Triangle 4 is (P1,P5,P6).
Computer Graphics (ii) OUTPUT element _10_ polygon Fill Area _7_opengl Polygon fill area function (top)