• Advertisement
Sign in to follow this  

GLSL Texturing Problem

This topic is 2771 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

from directly above

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:


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 && 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 && 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'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!

[Edited by - Total_Titillation on July 21, 2010 7:46:56 PM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement