Open GL Super Bible

Previous Table of Contents Next


Reference Section

glBegin

Purpose
Used to denote the beginning of a group of vertices that define one or more primitives.
Include File
<gl.h>
Syntax
void glBegin(GLenum mode);
Description
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.

Parameters

mode
GLenum: This value specifies the primitive to be constructed. It may be any of the values in Table 6-1.
Returns
None.

Example

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.

    glBegin(GL_POINTS)
            glVertex3f(0.0f, 0.0f, 0.0f); //plots point at origin
    glEnd();
See Also
glEnd, glVertex
Table 6-1 OpenGL Primitives Supported by glBegin()

Mode Primitive Type

GL_POINTS The specified vertices are used to create a single point each.
GL_LINES 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.
GL_LINE_STRIP 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.
GL_LINE_LOOP 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.
GL_TRIANGLES 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.
GL_TRIANGLE_STRIP 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.
GL_TRIANGLE_FAN 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.
GL_QUADS 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.
GL_QUAD_STRIP 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.
GL_POLYGON 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.

glCullFace

Purpose
Specifies whether the front or back of polygons should be eliminated from drawing.
Include File
<gl.h>
Syntax
void glCullFace(GLenum mode);
Description
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 winding).

Parameters

mode
GLenum: Specifies which face of polygons should be culled. May be either GL_FRONT or GL_BACK.
Returns
None.

Example

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
    glFrontFace(GL_CW);
    
    
    
    // Turn culling on if flag is set
    if(bCull)
           glEnable(GL_CULL_FACE);
       else
           glDisable(GL_CULL_FACE);
See Also
glFrontFace, glLightModel


Previous Table of Contents Next