#### Archived

This topic is now archived and is closed to further replies.

# use glNormal and GL_TRIANGLE_STRIP .. Possible ?

This topic is 5862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I would like to know if you could help me with a problem that I have with glNormal and GL_TRIANGLE_STRIP. I'm making a terrain. To do that, I use triangles strip. All works fine, but now, I would like to give values of normals to openGL. I've already calculated my normals and the probleme isn't there. I'm doing this :
  for (int z=0; z
When I execute this code, it generates a heightmap. But, I would like to know where to place the call for glNormal3f(). I know to do that if I use GL_TRIANGLES. I have to place it before the 3 glVertex call, but there, it's different. Have you an idea about how to do that ? sorry for my very bad english. Edited by - bestel on February 5, 2002 3:00:18 AM

##### Share on other sites
As long as you call it before each call to glVertex3f it'll be okay. Also, calling several functions per vertex is horribly slow, you may want to look into vertex arrays.

Edited by - siaspete on February 5, 2002 3:09:54 AM

##### Share on other sites
Thank you for your answer. I''m ok to call it before each glVertex()... but my real problem is that I dont'' know wich face will correspond with this kind of vertex.

5    6*---*|\  || \ ||  \||3  |4*---*|\  || \ ||  \||   |*---*1   2`

(sorry, it''s not very nice )

my code is making point1, point2, point3, point4 ...
My normals are stored in an array. So, do you think I have to call glNormal3f() before my point1 with the value of the normal of face(1,2,3) and then glNormal3f() before my point2 with the value of the normal of face(2,3,4), etc ... ?

##### Share on other sites
quote:

I''m ok to call it before each glVertex()... but my real problem is that I dont'' know wich face will correspond with this kind of vertex

It seems to me that you are calculating normals PER FACE. OpenGL wants normals PER VERTEX. You specify one normal for each vertex. To calculate the vertex normal, sum up the normals of all the faces surrounding the vertex, divide by the number of surrounding faces, and normalize the result. Once you have this working look into using vertex arrays, since you can render the whole terrain section with one DrawArrays or DrawElements instead of hundreds of glVertex, glTexCoord, and glNormal calls.

##### Share on other sites
i have the same issue.

i run my calculate normal function and do a glVertex, but as you move into the next triangle in the strip, it recalculates the value for the last vertex and overwrites, doesn''t it?

How do you average out the normals between triangles in the triangle strip? Make a vector class and multiply the current normal by newly calculated normal is my guess...

Yours might be bigger. Yours might be harder. BUT, mine is multi textured, bump-mapped, pixel shaded & fully user customizable!

##### Share on other sites
quote:
sum up the normals of all the faces surrounding the vertex, divide by the number of surrounding faces, and normalize the result.

Am I really obliged to divide by the number of face ? If I just sum up normals and normalize them, it should be okay ... true ?