Hi all!
I have searched for an answer for a few days and have not found. May be i am lost in terms and search with wrong keywords, i don’t know. Please help :slight_smile:

The problem is:
I have a little program to look at my scientific results. It draws two types of objects:

  1. set of cylinders
  2. surface, as a set of triangles

I draw set of cylinders using gluCylinder() function, and set up lights and so on. Thus I have a nice picture of my vector field distribution. Nice. There are 4 light to light up the scene, and there are nice shining, shades on cylinders etc

Then I add surface to the scene. The list of triangles is defined, and i use simple cycle across the list:

for(int q=0;q<s.size();q++)
glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
glVertex(s[q].A.x, s[q].A.y, s[q].A.z, 1.0f);
glVertex(s[q].B.x, s[q].B.y, s[q].C.z, 1.0f);
glVertex(s[q].C.x, s[q].C.y, s[q].B.z, 1.0f);

The result is good if i use
before. It is just carcass of the surface, OK.
But when i replace it with
to look on the surface as a solid body, rendering behaves very strange!
In more details: there is one color across all triangles, that changes from blue to black during rotation of the scene. Color of each triangle is the same, independent from it’s position in space (while i was waiting for some changing in color depending on it’s angle of rotation, like in cyliners i have drawn before).

Using GL_TRIANGLES instead of GL_POLYGONS doesn’t matter.

The result doesn’t depend on glShadeModel(GL_FLAT) or glFlatModel(GL_SMOOTH), doesn’t depend on positions of lights and many other parameters i have tried to change.

Please help me to understand where i am wrong or give me a path to look at. I am frustrated.

Thanks in advance.

You should have normals for the triangle surface, if you want to it to be lit properly.

Could you describe shortly how to do it please (a little example or at least a keyword to search in web)?

I mean i clearly understand what is normal and how to calculate it, however, there are two questions:

  1. what function to use?
  2. should i use normal vectors with direction strongly outside the surface, or could use normal vector without care of it’s direction (inside/outside)?

You should call glNormal before glVertex. The direction matters, it should point away from the surface point.

Got it, thanks!

D’oh! Will use ray-hull intersection algorithm.
If normal vectors are appointed randomly, the coloring is a kind of frustrating.

Thanks a lot for the answers!

I don’t quite follow, why should you use ray-hull intersection? You can easily compute normal for a triangle, assuming all of them are consistently oriented, and then compute vertex normals from triangle normals.