Sorry for all the posts, but I feel like I've done everything I could possibly do, and a little more, to fix this situation.
I want to load my terrain into the graphics card as a VBO, and then to use indices to draw it. Maybe I don't understand how indices work, but can anyone look at this code for me?
First, I load the vertices:
for(int x=0; x < m_mapWidth; ++x)
{
for(int z=0; z < m_mapLength; ++z)
{
int j=x+z*m_mapWidth;
textureData[2*j]=x/((float)m_mapWidth);
textureData[2*j+1]=1.0-(z/((float)m_mapLength));
mapData[3*j]=x;
mapData[3*j+1]=GetHeight(x, z);
mapData[3*j+2]=z;
}
}
So that should mean that if I go to mapData[3*(x+z*m_mapWidth)] then I have the point (x, Height(x, z), z), right? So then if I want to draw these points as a triangle strip, I need to draw them like:
5---4
|-/-|
3/--2
|-/-|
1/--0
Right? If so, then I don't understand why the following index doesn't work:
int index=0;
for(int z=0; z < m_mapWidth; ++z)
{
for(int x=0; x < m_mapLength; ++x)
{
m_indices[index++]=x+(z+1)*m_mapLength;
m_indices[index++]=x+z*m_mapLength;
}
}
I then draw (or try to draw) the terrain using
glDrawElements(GL_TRIANGLE_STRIP, m_mapLength*m_mapWidth*2, GL_UNSIGNED_SHORT, (GLvoid*)m_indices)
Where am I going wrong? The end result is a strip of correct terrain down the x-axis, but then there's a big trianglular prism of terrain that surrounds it, and a bunch of junk everywhere.
Thanks for the help, this is really frustrating me!