How to autogenerate Normals?

I’ve read through the docs and manuals i’ve found and they say something about autogenerating normals for better lighting - but where is this doc, manual or tutorial? Or does anyone have code for autogenerating normals? (glNormal3f…)
Ls

I think glEnable(GL_AUTO_NORMAL) that is. Building normals isn’t too complicated though, if you just want normals for a face, the normal is simply a normalized cross-product of two edges-vectors (?).

if you just want normals for a face, the normal is simply a normalized cross-product of two edges-vectors
What I want to know is that the two edge vertices form a plane, lets say a horizontal plane, the normal could point up or down so how does the cross product calculate which direction?

[This message has been edited by Tim Stirling (edited 11-28-2000).]

It depends on the order you specify the edges. Say you have a function that takes 3 vertices and determines the face normal. If you call the function like so GetNormal(v1, v2, v3); the normal will face one direction, but if you call it using GetNormal(v2,v1,v3) it’ll point in the opposite direction. The pseudo-code for the GetNormal function would look something like so…

Vector GetNormal(Vector v1, Vector v2, Vector v3)
{
Vector temp1, temp2;
Vector normal;

temp1 = v1 - v2;
temp2 = v2 - v3;

// assume * represents cross-product
normal = temp1 * temp2;  
normal.Normalize();

return normal;

}

[This message has been edited by Deiussum (edited 11-29-2000).]

Note that use glEnable(GL_AUTO_NORMAL) is not a good idea : it may eat lots of CPU/GPU cycles…
Use it for test/debug stuff to see how openGL works with normals then use normals table.

What do you mean with normals table?

the comment in the snippet of code is wrong. it is not a dot product it should be cross product.

Originally posted by hneed:
the comment in the snippet of code is wrong. it is not a dot product it should be cross product.

Oops. Fixed now. Not sure where my brain was when I typed that in.

If you stored the poly counterclockwise, take the crossproduct of to vectors that start at one vertex of it, and it will point towards the direction opengl also uses.

glEnable(GL_AUTO_NORMAL); doesn’t work.
Is there anything else to do for autogenerated normals ?

And what’s with the glNormal(); calls?

Have you read SDK help? Here is description from it:

GL_AUTO_NORMAL

If enabled, compute surface normal vectors analytically when either GL_MAP2_VERTEX_3 or GL_MAP2_VERTEX_4 is used to generate vertexes.

gl_AUTO_NORMAL is useful only for NURBS and Bezier surface.
It seems to be no automatic normal generation in OpenGL. There is only automatic normalizing of normals(making them 1-length)
glNormal works :slight_smile:

it is best to generate your own normals though, as computing the normals bogs down opengl (especially with bezier curves)

just my 2 cents

I think that GL_AUTO_NORMAL only works for the evaluators, and not for regular primitives. For those you need to call glNormal* with an appropriate normal.

j