# Thread: How to autogenerate Normals?

1. ## 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

2. ## Re: How to autogenerate Normals?

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 (?).

3. ## Re: How to autogenerate Normals?

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).]

4. ## Re: How to autogenerate Normals?

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...

Code :
```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).]

5. ## Re: How to autogenerate Normals?

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.

6. ## Re: How to autogenerate Normals?

What do you mean with normals table?

7. ## Re: How to autogenerate Normals?

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

8. ## Re: How to autogenerate Normals?

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.

9. ## Re: How to autogenerate Normals?

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.

10. ## Re: How to autogenerate Normals?

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

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

Page 1 of 2 12 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•