PDA

View Full Version : Texturing Problem



Henners
07-23-2010, 06:17 AM
I'm working on a terrain generator based on this demo (http://www.dhpoware.com/demos/glslTerrainTexturing.html).

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 (http://www.henryprescott.com/images/above.png)

view from the side (http://www.henryprescott.com/images/side.png)

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

glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);

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 &amp;&amp; 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));
else
n.x = 2.0f * (heightAtPixel(x, z) - heightAtPixel(x + 1, z));

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

n.y = 2.0f * m_gridSpacing;
n.normalize();
}


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);

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

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

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

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

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_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!