Used to denote the beginning of a group of vertices that define one or more primitives.
void glBegin(GLenum mode);
This function is used in conjunction with glEnd
to delimit the vertices of an OpenGL primitive. Multiple vertices sets
may be included within a single glBegin/glEnd pair, as long as they are
for the same primitive type. Other settings may also be made with
additional OpenGL commands that affect the vertices following them. Only
these OpenGL functions may be called within a glBegin/glEnd sequence:
glVertex, glColor, glIndex, glNormal, glEvalCoord, glCallList,
glCallLists, glTexCoord, glEdgeFlag, and glMaterial.
GLenum: This value specifies the primitive to be constructed. It may be any of the values in Table 6-1.
You can find this ubiquitous function in literally every example and supplementary sample in this chapter. The following code shows a single point being drawn at the origin of the x,y,z coordinate system.
glVertex3f(0.0f, 0.0f, 0.0f); //plots point at origin
Table 6-1 OpenGL Primitives Supported by glBegin()
The specified vertices are used to create a single point each.
The specified vertices are used to create line segments. Every two vertices specify a single and separate line segment. If the number of vertices is odd, the last one is ignored.
The specified vertices are used to create a line strip. After the first vertex, each subsequent vertex specifies the next point to which the line is extended.
Behaves as GL_LINE_STRIP, except a final line segment is drawn between the last and the first vertex specified. This is typically used to draw closed regions that may violate the rules regarding GL_POLYGON usage.
The specified vertices are used to construct triangles. Every three vertices specify a new triangle. If the number of vertices is not evenly divisible by three, the extra vertices are ignored.
The specified vertices are used to create a strip of triangles. After the first three vertices are specified, each of any subsequent vertices is used with the two preceding ones to construct the next triangle. Each triplet of vertices (after the initial set) is automatically rearranged to ensure consistent winding of the triangles.
The specified vertices are used to construct a triangle fan. The first vertex serves as an origin, and each vertex after the third is combined with the foregoing one and the origin. Any number of triangles may be fanned in this manner.
Each set of four vertices is used to construct a quadrilateral (a four-sided polygon). If the number of vertices is not evenly divisible by four, the remaining ones are ignored.
The specified vertices are used to construct a strip of quadrilaterals. One quadrilateral is defined for each pair of vertices after the first pair. Unlike the vertex ordering for GL_QUADS, each pair of vertices is used in the reverse order specified, to ensure consistent winding.
The specified vertices are used to construct a convex polygon. The polygon edges must not intersect. The last vertex is automatically connected to the first vertex to insure the polygon is closed.
Specifies whether the front or back of polygons should be eliminated from drawing.
void glCullFace(GLenum mode);
This function disables lighting, shading, and
color calculations and operations on either the front or back of a
polygon. Eliminates unnecessary rendering computations because the back
side of polygons will never be visible regardless of rotation or
translation of the objects. Culling is enabled or disabled by calling
glEnable and glDisable with the GL_CULL_FACE parameter. The front and
back of the polygon are defined by use of glFrontFace() and by the order
in which the vertices are specified (clockwise or counterclockwise
GLenum: Specifies which face of polygons should be culled. May be either GL_FRONT or GL_BACK.
The following code (from the TRIANGLE example in this chapter) shows how the color and drawing operations are disabled for the inside of the cone when the Boolean variable bCull is set to True.
// Clockwise-wound polygons are front facing; this is reversed
// because we are using triangle fans
// Turn culling on if flag is set