Contents / Previous / Next


Normal Vectors

A normal vector (or normal, for short) is a vector that points in a direction that's perpendicular to a surface. For a flat surface, one perpendicular direction suffices for every point on the surface, but for a general curved surface, the normal direction might be different at each point.

With OpenGL, you can specify a normal for each vertex.
Normal vectors are used, for example, to determine how much light the object receives.

You use glNormal*() to set the current normal to the value of the argument passed in: void glNormal3{bsidf}(TYPEnx, TYPEny, TYPEnz);
void glNormal3{bsidf}v(const TYPE *v);

The b, s, and i versions scale their parameter values linearly to the range [-1.0,1.0].

Subsequent calls to glVertex*() cause the specified vertices to be assigned the current normal. Often, each vertex has a different normal, which necessitates a series of alternating calls like this:

glBegin (GL_POLYGON);
   glNormal3fv(n0);
   glVertex3fv(v0);
   glNormal3fv(n1);
   glVertex3fv(v1);
   glNormal3fv(n2);
   glVertex3fv(v2);
   glNormal3fv(n3);
   glVertex3fv(v3);
glEnd();

Since normal vectors indicate direction only thier length does not matter.
Eventually they have to be converted to having a length of 1 before lighting calculations are performed.
If you specify nonunit-length normals, you should have OpenGL automatically normalize your normal vectors after the transformations. To do this, call glEnable() with GL_NORMALIZE as its argument. By default, automatic normalization is disabled.
Note that in some implementations of OpenGL, automatic normalization requires additional calculations that might reduce the performance of your application.

-> See also: Finding normals.