glShadeModel

The glShadeModel function selects flat or smooth shading.

void glShadeModel(
  GLenum mode  
);
 

Parameters

mode
A symbolic value representing a shading technique. Accepted values are GL_FLAT and GL_SMOOTH. The default is GL_SMOOTH.

Remarks

OpenGL primitives can have either flat or smooth shading. Smooth shading, the default, causes the computed colors of vertices to be interpolated as the primitive is rasterized, typically assigning different colors to each resulting pixel fragment. Flat shading selects the computed color of just one vertex and assigns it to all the pixel fragments generated by rasterizing a single primitive. In either case, the computed color of a vertex is the result of lighting, if lighting is enabled, or it is the current color at the time the vertex was specified, if lighting is disabled.

Flat and smooth shading are indistinguishable for points. Counting vertices and primitives from one, starting when glBegin is issued, each flat-shaded line segment i is given the computed color of vertex i + 1, its second vertex. Counting similarly from one, each flat-shaded polygon is given the computed color of the vertex listed in the following table. This is the last vertex to specify the polygon in all cases except single polygons, where the first vertex specifies the flat-shaded color.

Primitive Type of Polygon i Vertex
Single polygon (iº1) 1
Triangle strip i + 2
Triangle fan i + 2
Independent triangle 3i
Quad strip 2i + 2
Independent quad 4i

Flat and smooth shading are specified by glShadeModel with mode set to GL_FLAT and GL_SMOOTH, respectively.

The following function retrieves information related to glShadeModel:

glGet with argument GL_SHADE_MODEL

Error Codes

The following are the error codes generated and their conditions.

Error Code Condition
GL_INVALID_ENUM mode was any value other than GL_FLAT or GL_SMOOTH.
GL_INVALID_OPERATION glShadeModel was called between a call to glBegin and the corresponding call to glEnd.

QuickInfo

  Windows NT: Use version 3.5 and later.
  Windows: Use Windows 95 and later.
  Windows CE: Unsupported.
  Header: Declared in gl.h.
  Import Library: Link with opengl32.lib.

See Also

glBegin, glColor, glEnd, glLight, glLightModel