I understand that calculating a normal is a rather simple concept, but for some reason, I can't wrap my head around generating normals for a triangle strip. What I have is a heightmap and I need normals for lighting. The whole thing is rendered using triangle strips.

Just in case you need a visual, take a look at this code I used to generate vertices and texture coordinates.

void heightmap_t::build_vertices() { float X, Y; float x, y, z; bool switch_sides = No; /* Sanity check */ if( !m_height_data ) return; /* * First Pass: determine total number of vertices needed */ m_vertex_count = 0; for ( X = 0; X <= m_width; X += m_polygon_scale ) { /* Are we switching sides? */ if( switch_sides ) { for( Y = m_height; Y >= 0; Y -= m_polygon_scale ) { m_vertex_count += 2; } } else { for( Y = 0; Y <= m_height; Y += m_polygon_scale ) { m_vertex_count += 2; } } /* Switch the direction the columb renders to allow fluid tri-strips */ switch_sides = !switch_sides; } /* * Second Pass: Allocate and generate vertices */ switch_sides = No; m_vertices = new float[m_vertex_count*3]; m_texcoords = new float[m_vertex_count*2]; int v = 0; for ( X = 0; X <= m_width; X += m_polygon_scale ) { /* Are we switching sides? */ if( switch_sides ) { /* Columns */ for( Y = m_height; Y >= 0; Y -= m_polygon_scale ) { /* Bottom left vertex */ x = X; y = get_height( X, Y ); z = Y; /* Set texture and vertex coordinates */ m_texcoords[(v*2)+0] = ( x / float( m_width ) ) * 50.0f; m_texcoords[(v*2)+1] = -( z / float( m_height ) ) * 50.0f; m_vertices[(v*3)+0] = x; m_vertices[(v*3)+1] = y; m_vertices[(v*3)+2] = z; v++; /* Bottom right vertex */ x = X + m_polygon_scale; y = get_height( X + m_polygon_scale, Y ); z = Y; /* Set texture and vertex coordinates */ m_texcoords[(v*2)+0] = ( x / float( m_width ) ) * 50.0f; m_texcoords[(v*2)+1] = -( z / float( m_height ) ) * 50.0f; m_vertices[(v*3)+0] = x; m_vertices[(v*3)+1] = y; m_vertices[(v*3)+2] = z; v++; } } else { for( Y = 0; Y <= m_height; Y += m_polygon_scale ) { /* Bottom right vertex */ x = X + m_polygon_scale; y = get_height( X + m_polygon_scale, Y ); z = Y; /* Set texture and vertex coordinates */ m_texcoords[(v*2)+0] = ( x / float( m_width ) ) * 50.0f; m_texcoords[(v*2)+1] = -( z / float( m_height ) ) * 50.0f; m_vertices[(v*3)+0] = x; m_vertices[(v*3)+1] = y; m_vertices[(v*3)+2] = z; v++; /* Bottom left vertex */ x = X; y = get_height( X, Y ); z = Y; /* Set texture and vertex coordinates */ m_texcoords[(v*2)+0] = ( x / float( m_width ) ) * 50.0f; m_texcoords[(v*2)+1] = -( z / float( m_height ) ) * 50.0f; m_vertices[(v*3)+0] = x; m_vertices[(v*3)+1] = y; m_vertices[(v*3)+2] = z; v++; } } /* Switch the direction the columb renders to allow fluid tri-strips */ switch_sides = !switch_sides; } /* Use the vertex data to generate a VBO */ glGenBuffers( 3, m_vbo ); glBindBuffer( GL_ARRAY_BUFFER, m_vbo[0] ); glBufferData( GL_ARRAY_BUFFER, m_vertex_count*3*sizeof(float), m_vertices, GL_STATIC_DRAW ); glBindBuffer( GL_ARRAY_BUFFER, m_vbo[1] ); glBufferData( GL_ARRAY_BUFFER, m_vertex_count*2*sizeof(float), m_texcoords, GL_STATIC_DRAW ); }

This is based off of an old tutorial from gametutorials.com. A bit of a shame that they didn't calculate normals in the heightmap tutorial...

My initial idea was to take each triangle individually, and calculate face normals first. Then I get confused after the 2nd part. Do I like go each vertex and match up vertices with matching coordinates, add the normals and re-normalize? That's the part I'm having trouble wrapping my head around. My brain is a bit fried at the moment, and I'm in a 24-hour coding competition right now. Any ideas? Thanks.

Shogun.