use glNormal and GL_TRIANGLE_STRIP .. Possible ?

Started by
4 comments, last by Bestel 22 years, 2 months ago
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<length-1; z++)
{
  glBegin(GL_TRIANGLE_STRIP);
  for (int x=0; x<width-1; x++)
  {
    glTexCoord2f(x, z);
    glVertex3f(x, heightMap[x][z], z);
    glTexCoord2f(x, z+1);
    glVertex3f(x, heightMap[x][z+1], z+1);
  }
  glEnd();
}
    
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
Advertisement
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
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 ... ?
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.
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!
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 ?

This topic is closed to new replies.

Advertisement