# normals for triangle strips (oGL)

• 03-25-2003
Perspective
normals for triangle strips (oGL)
where do you specify normals when drawing triangle strips? what i mean is that with 4 verticies i draw 2 triangles having (potentially) 2 different normals. if i have 4 calls to glVertex(), at what point do i specify the normal of the second triangle.

ex)
Code:

``` glNormal( .... ); // normal of first triangle glVertex( ... ); // vertex 1 glVertex( ... ); // vertex 2 glVertex( ... ); // vertex 3 glVertex( ... ); // vertex 4```
vertices 1,2,3 make up a triangle with one normal and 2,3,4 are a triangle with a different normal. at which line can i call glNormal() to specify the second normal so that both triangles have their own distinct normal??
• 03-25-2003
Silvercord
If you are drawing a triangle strip then I think it would be between 3 and 4. I assumed point 1 was the middle of the fan (therefore triangle 2 is really points 1, 3 and 4 not 2,3,4).

Code:

``` glNormal( .... ); // normal of first triangle glVertex( ... ); // vertex 1 glVertex( ... ); // vertex 2 glVertex( ... ); // vertex 3, finishes first triangle glNormal( ... ); //normal of second triangle glVertex( ... ); // vertex 4```
• 03-25-2003
Perspective
Quote:

Originally posted by Silvercord
If you are drawing a triangle strip then I think it would be between 3 and 4. I assumed point 1 was the middle of the fan (therefore triangle 2 is really points 1, 3 and 4 not 2,3,4).

strips are different from fans, there is no middle point. strips are drawn like this...
Code:

```    (1)----(2)             /           /         /     (3)----(4)```
so 1,2,3 make up the first triangle, and 2,3,4 make up the second.

i am currently declaring the second normal before the 4th vertex but i'm not sure (judging by lighting if :rolleyes: ) if the entire second triangle is reciving that normal, or just the last vertex.
• 03-25-2003
Silvercord
well I see what you are saying now. The first triangle is officially done being drawn after the 3rd vertex (in fact this should never change whether you are doing fans or strips) so I would still say set the second between 3 and 4 (as you have done). I'm trying to think of how OpenGL handles things. It is a state machine, so that means the first normal is used for every vertex set until the next glnormal is called. i'm not sure if the entire second triangle receives the normal (in order for the second triangle to receive the second vertex i would think all 3 vertices would need to receive the same normal) or not because it seems just the last vertex is getting the normal for the second triangle, but not vertices 2 and 3. Can you attach the executable of what you have so far? Maybe you can make it rotate or something so we can get a clear view of both triangles?

EDIT: oh this is for your terrain thing right?
• 03-25-2003
Perspective
well, i was thinking along the same lines you are. the normale last specified when the triangle is completed should act on that triangle. i dont know for sure if we are right but it seems to look the best when i put the second normal before the last vertex. im gonna go with that for now.

i will post an executable when i combine the terrain gen with the flight engine. :)
• 03-26-2003
Silvercord
Sounds good to me, keep up the good work.
• 04-01-2003
confuted
Here's my caveat: It's been a while since I've done much with 3D.

Now, having said that, I believe that if you don't want sharp edges between the two triangles, you need to interpolate between the two normals when determining the lighting for different points. You appear to be doing flat shading here, which might be what you want, but Gourand (spelling butchered, someone correct me) looks nicer. Anyway, I don't know OpenGL so I can't tell you exactly what it is doing with your normals, but I thought I'd add my comment.
• 04-01-2003
Silvercord
Yeah but whether you are setting surface normals for lighting (flat shading) or setting the normals at each vertex (smooth shaded) the problem is still basically the same: where in the hell do you set the normals.
• 04-01-2003
confuted
once again, I have no experience with OpenGL, so this probably isn't going to help you, but even if it doesn't, it will probably help some other intrepid programmer out there.

Anyway...
I'll use this triangle for this...
Code:

```      a       /\       /  \   c /____\b```
1) find the vectors which describe two sides, for example, side ac and side ab
2) take the crossproduct of those two sides, which is the normal of the face
3) at this point, if you are doing flat shading, normalize your normal and continue on with your lighting routines. If you aren't doing flat shading, don't normalize the normal yet.
4) For each vertex, add the (unnormalized) normals of every face sharing the vertex
5) normalize this normal to find the normal for the vertex (even though technically, a normal is defined as a vector perpendicular to a plane so a vertex can't have a normal)

So, perhaps this will help you, probably it won't. It sounds like you know what you're doing, but perhaps OpenGL provides a way for you to compute the normals yourself (like that up there) and then store it in the OpenGL data stuctures. Anyway, good luck.

Edit: Fixed the triangle because it looked bad