Graphics Reference
In-Depth Information
7.1.3
Triangles
The triangle is one of the most important primitives in computer graphics. Tri-
angles can be used to approximate many geometric objects in 2D and 3D. For
example, we have already experienced approximating 2D circles with triangles.
Figure 7.3 shows approximating a tiger's geometric shape with triangles, and Fig-
ure 7.4 shows approximating a teapot's geometric shape with strips of triangles
that are arranged in an orderly manner. There are many drawing commands de-
fined to optimize the drawing of triangles, some examples of which include the
following.
Figure 7.3.
Approximat-
ing a tiger with triangles.
•
Triangle list.
An application program will specify 3
n
vertices and request
the graphics API to draw
n
individual triangles.
•
Triangle fan.
An application program will specify
n
2 vertices and re-
quest the graphics API to draw
n
triangles where all triangles are connected
to the first specified vertex. Figure 7.5 shows an example of specifying a
triangle fan.
+
Figure 7.4.
Approxi-
mating a teapot with trian-
gle strips.
•
Triangle strips.
2 vertices and
request the graphics API to draw
n
connected triangles. Figure 7.6 shows
an example of specifying a triangle strip.
An application program will specify
n
+
V
2
V
1
V
3
Figures 7.5 and 7.6 are examples of how the triangles can be specified. In general,
the exact order is highly graphics API-dependent. In addition, each graphics API
may have additional requirements/restrictions to ensure clockwise and/or coun-
terclockwise ordering of individual triangles in the collection.
V
5
V
4
Figure 7.5.
Specifying a
triangle fan.
V
1
V
4
V
6
V
2
Attributes of triangles.
A triangle can have up to three types of attributes: per-
vertex, per-edge, and per-drawing command attributes. The per-vertex attributes
of a triangle are identical to the per-vertex attributes of a line. The per-edge at-
tributes of a triangle define the appearance of the edges of a triangle. Examples
include width, style, color, and so on. Because triangles are meant to approxi-
mate more complex objects, edge attributes are typically not supported by graph-
ics APIs. The per-drawing command attributes for a triangle are similar to those
of a line segment.
V
3
V
5
V
7
Figure 7.6.
Specifying a
triangle strip.
•
Triangle color.
When Gouraud shading, illumination computation, and
texture mapping are all disabled, this color defines the color for
flat shading
the entire triangle (or triangles in the triangle fan/strip).
•
Material property.
This is identical to that of the line.
Search WWH ::
Custom Search