The information in this article applies to:
SUMMARYIn a Microsoft Win32 OpenGL application, it is common practice to construct objects with the glBegin function followed by several calls to glVertex. For example, to create a flat polygon in three-dimensional space, you could write this code:
Now, if you want to implement a light source or multiple light sources in
your OpenGL application, it is important that you include a call to the
glNormal function between the calls to glBegin and glEnd so that the normal vector can be used by OpenGL when calculating the color to use when filling the polygon.
You can perform a vector cross product on two vectors to obtain a third vector that is perpendicular to the plane containing the two vectors. Using a vector cross product, you can calculate the vector normal to the polygon and use that value in your call to glNormal. MORE INFORMATIONUsing cross product math on two vectors of a polygon, you can obtain a vector that is perpendicular to the polygon. Two sides of a polygon describe two vectors in the plane of the polygon. With those two vectors, you can calculate a vector that is perpendicular to the polygon. The length of the normal vector calculated will not be unit length, and the normal vector needs to be unit length. Therefore, you need to call glEnable(GL_NORMALIZE) when you initialize your OpenGL application, so that normal vectors specified with glNormal are scaled to unit length after transformation. Code SampleYou can use the following function to calculate a normal vector for a polygon. You need to give it three points of the polygon and the points should be given in clock-wise order when you are facing the front of the polygon:
Code to Call and Use the CalculateVectorNormal FunctionHere is an example of how you might call and use the function:
Additional query words: graphics light
Keywords : kbNTOS400 kbWinOS2000 kbSDKWin32 kbWinOS98 |
Last Reviewed: December 20, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |