0% found this document useful (0 votes)
16 views26 pages

L7

Uploaded by

hhhhhcccc25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views26 pages

L7

Uploaded by

hhhhhcccc25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

1

Fill-Area Primitives

2
Fill-Area Primitives

1. Fill-Area Primitives
2. Polygon Fill Areas
3. OpenGL Polygon Fill-Area Functions

3
Fill-Area Primitives

• Another useful construct, besides points, straight-


line segments, and curves, for describing
components of a picture is an area that is filled with
some solid color or pattern.

• A picture component of this type is typically


referred to as a fill area or a filled area.

4
Fill-Area Primitives

5
Fill-Area Primitives

6
Fill-Area Primitives

• Objects described with a set of polygon surface


patches are usually referred to as standard
graphics objects, or just graphics objects.

7
Polygon Fill Areas

• Mathematically defined, a polygon is a plane


figure specified by a set of three or more
coordinate positions, called vertices, that are
connected in sequence by straight-line segments,
called the edges or sides of the polygon.

• Examples of polygons include triangles,


rectangles, octagons, and decagons.
8
Polygon Fill Areas

• Sometimes, any plane figure with a closed-polyline


boundary is alluded to as a polygon, and one with no
crossing edges is referred to as a standard polygon or a
simple polygon.

• In an effort to avoid ambiguous object references, we will


use the term polygon to refer only to those planar shapes
that have a closed-polyline boundary and no edge
crossings.

9
OpenGL Polygon Fill-Area Functions
• With one exception, the OpenGL procedures for specifying
fill polygons are similar to those for describing a point or a
polyline.

• A glVertex function is used to input the coordinates for a


single polygon vertex, and a complete polygon is described
with a list of vertices placed between a glBegin/glEnd
pair.

• However, there is one additional function that we can use


for displaying a rectangle that has an entirely different
format.

10
OpenGL Polygon Fill-Area Functions

• By default, a polygon interior is displayed in a solid color, determined


by the current color settings.

• As options, we can fill a polygon with a pattern and we can display


polygon edges as line borders around the interior fill.

• There are six different symbolic constants that we can use as the
argument in the glBegin function to describe polygon fill areas.

• These six primitive constants allow us to display a single fill polygon,


a set of unconnected fill polygons, or a set of connected fill polygons.

11
OpenGL Polygon Fill-Area Functions

• In OpenGL, a fill area must be specified as a convex


polygon.

• Thus, a vertex list for a fill polygon must contain at


least three vertices, there can be no crossing edges,
and all interior angles for the polygon must be less
than 180◦.

12
OpenGL Polygon Fill-Area Functions
• Because graphics displays often include rectangular fill areas,
OpenGL provides a special rectangle function that directly accepts
vertex specifications in the xy plane.
• In some implementations of OpenGL, the following routine can be
more efficient than generating a fill rectangle using glVertex
specifications:
glRect* (x1, y1, x2, y2);
• One corner of this rectangle is at coordinate position (x1, y1), and the
opposite corner of the rectangle is at position (x2, y2).

• Suffix codes for glRect specify the coordinate data type and whether
coordinates are to be expressed as array elements.
• These codes are i (for integer), s (for short), f (for float), d (for
double), and v (for vector). The rectangle is displayed with edges
parallel to the xy coordinate axes.
13
OpenGL Polygon Fill-Area Functions

• As an example, the following statement defines the square


shown in Figure 21:
glRecti (200, 100, 50, 250);

• If we put the coordinate values for this rectangle into


arrays, we can generate the same square with the following
code:
int vertex1 [ ] = {200, 100};
int vertex2 [ ] = {50, 250};
glRectiv (vertex1, vertex2);

14
OpenGL Polygon Fill-Area Functions

15
OpenGL Polygon Fill-Area Functions

• Each of the other six OpenGL polygon fill primitives


is specified with a symbolic constant in the glBegin
function, along with a a list of glVertex commands.

• With the OpenGL primitive constant GL_POLYGON,


we can display a single polygon fill area such as
that shown in Figure 22(a).

16
OpenGL Polygon Fill-Area Functions

17
OpenGL Polygon Fill-Area Functions
• For this example, we assume that we have a list of six
points, labeled p1 through p6, specifying two-dimensional
polygon vertex positions in a counterclockwise ordering.
• Each of the points is represented as an array of (x, y)
coordinate values:
glBegin (GL_POLYGON);
glVertex2iv (p1);
glVertex2iv (p2);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5);
glVertex2iv (p6);
glEnd ( );
18
OpenGL Polygon Fill-Area Functions
• If we reorder the vertex list and change the
primitive constant in the previous code example
to GL_TRIANGLES, we obtain the two separated
triangle fill areas in Figure 22(b):
glBegin (GL_TRIANGLES);
glVertex2iv (p1);
glVertex2iv (p2);
glVertex2iv (p6);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5);
glEnd ( );
19
OpenGL Polygon Fill-Area Functions
• By reordering the vertex list once more and
changing the primitive constant to
GL_TRIANGLE_STRIP, we can display the set of
connected triangles shown in Figure 22(c):
glBegin (GL_TRIANGLE_STRIP);
glVertex2iv (p1);
glVertex2iv (p2);
glVertex2iv (p6);
glVertex2iv (p3);
glVertex2iv (p5);
glVertex2iv (p4);
glEnd ( ); 20
OpenGL Polygon Fill-Area Functions
• Another way to generate a set of connected triangles is to use
the “fan” approach illustrated in Figure 22(d), where all triangles
share a common vertex.

• We obtain this arrangement of triangles using the primitive


constant GL_TRIANGLE_FAN and the original ordering of our six
vertices:
glBegin (GL_TRIANGLE_FAN);
glVertex2iv (p1);
glVertex2iv (p2);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5);
glVertex2iv (p6);
glEnd ( ); 21
OpenGL Polygon Fill-Area Functions

• Besides the primitive functions for triangles and a


general polygon, OpenGL provides for the
specifications of two types of quadrilaterals (four-
sided polygons).

22
OpenGL Polygon Fill-Area Functions

23
OpenGL Polygon Fill-Area Functions
• With the GL_QUADS primitive constant and the
following list of eight vertices, specified as two-
dimensional coordinate arrays, we can generate the
display shown in Figure 23(a):
glBegin (GL_QUADS);
glVertex2iv (p1);
glVertex2iv (p2);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5);
glVertex2iv (p6);
glVertex2iv (p7);
glVertex2iv (p8);
glEnd ( ); 24
OpenGL Polygon Fill-Area Functions
• Rearranging the vertex list in the previous quadrilateral
code example and changing the primitive constant to
GL_QUAD_STRIP, we can obtain the set of connected
quadrilaterals shown in Figure 23(b):
glBegin (GL_QUAD_STRIP);
glVertex2iv (p1);
glVertex2iv (p2);
glVertex2iv (p4);
glVertex2iv (p3);
glVertex2iv (p5);
glVertex2iv (p6);
glVertex2iv (p8);
glVertex2iv (p7);
glEnd ( ); 25
THANK YOU
26

You might also like