Lighting on Objects

Started by
13 comments, last by Geometrian 16 years, 8 months ago
I'll read up on it. Can you point me to some resources? The problem you described is exactly my problem--can you tell me how to set the normals?

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Advertisement
http://www.lighthouse3d.com/opengl/terrain/index.php3?normals
I didn't spend much time searching for this, but it seems to be a short, clear guide to calculating normals for a polygon. You'll need to do a cross product to find the perpendicular, then normalize it (set it to length 1) for use in OpenGL.

http://www.glprogramming.com/red/chapter02.html#name5
Here's how the redbook says to declare normals. Their syntax here is a little confusing, but more simply: your typical command will be void glNormal3f(x, y, z);
You call this before each vertex, or just before each polygon for a flat polygon. In the case of faceted gems, the sides are flat and will have 1 normal per polygon, but for smooth objects you supply a normal per vertex, which is interpolated across the polygon and makes it look smoother.
You set the normal of a vertex with glNormal3d(), like so:

glNormal3d(0.0,0.0,1.0);
glVertex3d(123.0,123.0,123.0);


This Normal points in the z direction. The normal should be normalized for the lighting calculations to work as they should.

More on OpenGL lighting.
OK, give me a few minutes to implement it...

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Excellent. That works! Thanks!
G

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

This topic is closed to new replies.

Advertisement