Archived

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

Bestel

glNormal with triangle strip, possible ?

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<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 ? I've posted this message in the GameDev OpenGL forum and A guy told me to do a call to glNormal3f() before each glVertex()... I'm okay to do this but, ...
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 ... ? Sorry for my very bad english. I hope that you can understand it Edited by - bestel on February 5, 2002 1:02:05 PM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you want the terrain look rounded and lit smoothly, you should take all the faces that the vertex is a part of and avergae the face normals together. Then call glNormal before every glVertex call.

Share this post


Link to post
Share on other sites
tsss. pourquoi les français s''excusent-ils toujours de mal parler la langue du secoueur de lance ? Euh de Shakespeare, pardon

If you use flat shading, you have to define the normal once per triangle, which in OpenGL means once before the last vertex of the triangle is rendered. For example in triangle strip, the normal have to be define before the 3rd vertex and then before every following vertex.

If you use smooth shading, you have to define the normal once per vertex, eg before every vertex.

Remember that in OpenGL, every vertex sent to GL machine (eg call to glVertex) causes the render. That is, to define colors, texture coords, normals, etc, you have to do every call (to glColor, glTexCoord, etc) BEFORE glVertex.

Share this post


Link to post
Share on other sites
I''m using smooth shading. So, if I have well understood, it means for example that I have to compute the average normal of all the yellow face and call the glNormal with this value before My glVertex() Call for the red point.

Is it true ?

Share this post


Link to post
Share on other sites
Smooth shading, ok
glShadeModel(GL_SMOOTH);


Yes that''s exactly that.

The normal is obtained by meaning all the normals of the neighbour triangles.

And of course for each triangle the normal has to be computed via a cross product.

Share this post


Link to post
Share on other sites