Texturing Problem

I’m working on a terrain generator based on this demo.

I have changed the demo so that it generates a few heightmaps that can be placed side by side.

The problem I am having is that at the seems gaps appear even though the vertex is in the same position, as you can see in the following screenshots.

view from above

view from the side

I’m not sure why this is happening, but I thought it might be something to do with culling, as I am using:


But I’m fairly certain that the normals are being calculated correctly using this method:

void HeightMap::normalAtPixel(int x, int z, Vector3 &n) const
if (x > 0 && x < m_size - 1)
n.x = heightAtPixel(x - 1, z) - heightAtPixel(x + 1, z);
else if (x > 0)
n.x = 2.0f * (heightAtPixel(x - 1, z) - heightAtPixel(x, z));
n.x = 2.0f * (heightAtPixel(x, z) - heightAtPixel(x + 1, z));

if (z &gt; 0 && z &lt; m_size - 1)
    n.z = heightAtPixel(x, z - 1) - heightAtPixel(x, z + 1);
else if (z &gt; 0)
    n.z = 2.0f * (heightAtPixel(x, z - 1) - heightAtPixel(x, z));
    n.z = 2.0f * (heightAtPixel(x, z) - heightAtPixel(x, z + 1));

n.y = 2.0f * m_gridSpacing;


Each heightmap is rendered on its own using triangle strips:

void Terrain::terrainDraw()
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer);

glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(6 * sizeof(float)));

glNormalPointer(GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(3 * sizeof(float)));

glVertexPointer(3, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(0));

if (use16BitIndices())
    glDrawElements(GL_TRIANGLE_STRIP, m_totalIndices, GL_UNSIGNED_SHORT, BUFFER_OFFSET(0));
    glDrawElements(GL_TRIANGLE_STRIP, m_totalIndices, GL_UNSIGNED_INT, BUFFER_OFFSET(0));


glBindBuffer(GL_ARRAY_BUFFER, 0);


I have tried rendering the heightmap the camera is over last, as well as changing glDepthFunc() but this doesn’t solve the problem.

I’m guessing that if I copied the vertexes into a new VBO and rendered one big heightmap I wouldn’t have this problem, but I want to keep them separate.

Any help would be much appreciated, thank you!