# continous display lists to render a terrain! how?

hello, i have a problem here on a terrain rendering… i just started using
display lists and i wanted to divide the heightmap in 4 continous display
lists!
well to prepare a single display list for the heightmap i did nothing more
than this:

unsigned int list = glGenLists(NumberOfLists);

glNewList(list, GL_COMPILE);

glBegin(GL_TRIANGLES);
for (j=0; j<map_height; j++)
{
for (i=0; i<map_width; i++)
{
for (ti=0; ti<2; ti++)
{
glVertex3fv(Triangles[i][j][ti].Vertex[0]);
glVertex3fv(Triangles[i][j][ti].Vertex[1]);
glVertex3fv(Triangles[i][j][ti].Vertex[2]);
}
}
glEnd();

glEndList();

this would give me a display list for the heightmap…
well this was slow and i heard that dividing the display list is smaller
display lists would make things faster…
then i tried it!

im trying to divide it in 4 parts… the problem is this:

| | |

1 2
3 4

it seems to me that it only renders two parts of the terrain… sumtin like
1 & 4, or 2 & 3… always in the diagonal line…
here is the code i do: can anyone tell me what can be wrong or what have i
missed?

void CLandscape::CompileLandscape(int index)
{
GLuint list;
GLuint list2;
GLuint list3;
GLuint list4;

ListIndices = new unsigned int[NumberOfLists];

list = glGenLists(NumberOfLists);
ListIndices[0] = list;

glNewList(list, GL_COMPILE);

FullTerrainTexture.bind();

glBegin(GL_TRIANGLES);
for(int z = 0; z < mapHeight/4; z++)
{
for(int x = 0; x < mapWidth/4; x++)
{

for (int j=0; j<2; j++)
{
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(Triangles[x][z][j].Vertex[0].u,
Triangles[x][z][j].Vertex[0].v);
glNormal3fv(VertexNormals[x][z]);
glVertex3fv(Triangles[x][z][j].Vertex[0]);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(Triangles[x][z][j].Vertex[1].u,
Triangles[x][z][j].Vertex[1].v);
glNormal3fv(VertexNormals[x][z+1]);
glVertex3fv(Triangles[x][z][j].Vertex[1]);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(Triangles[x][z][j].Vertex[2].u,
Triangles[x][z][j].Vertex[2].v);
glNormal3fv(VertexNormals[x+1][z+1]);
glVertex3fv(Triangles[x][z][j].Vertex[2]);
}
}
}
glEnd();

glEndList();

// Prepare second display list.

list2=list+1;
ListIndices[1] = list2;

glNewList(list2, GL_COMPILE);

FullTerrainTexture.bind();

glBegin(GL_TRIANGLES);
for(z = mapHeight/4; z < mapHeight/2; z++)
{
for(int x = mapWidth/4; x < mapWidth/2; x++)
{

for (int j=0; j<2; j++)
{
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(Triangles[x][z][j].Vertex[0].u,
Triangles[x][z][j].Vertex[0].v);
glNormal3fv(VertexNormals[x][z]);
glVertex3fv(Triangles[x][z][j].Vertex[0]);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(Triangles[x][z][j].Vertex[1].u,
Triangles[x][z][j].Vertex[1].v);
glNormal3fv(VertexNormals[x][z+1]);
glVertex3fv(Triangles[x][z][j].Vertex[1]);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(Triangles[x][z][j].Vertex[2].u,
Triangles[x][z][j].Vertex[2].v);
glNormal3fv(VertexNormals[x+1][z+1]);
glVertex3fv(Triangles[x][z][j].Vertex[2]);
}
}
}
glEnd();

glEndList();

// Prepare third display list.

list3=list+2;
ListIndices[2] = list3;

glNewList(list3, GL_COMPILE);

FullTerrainTexture.bind();

glBegin(GL_TRIANGLES);
for(z = mapHeight/2; z < mapHeight-(mapHeight/4); z++)
{
for(int x = mapWidth/2; x < mapWidth-(mapWidth/4); x++)
{

for (int j=0; j<2; j++)
{
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(Triangles[x][z][j].Vertex[0].u,
Triangles[x][z][j].Vertex[0].v);
glNormal3fv(VertexNormals[x][z]);
glVertex3fv(Triangles[x][z][j].Vertex[0]);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(Triangles[x][z][j].Vertex[1].u,
Triangles[x][z][j].Vertex[1].v);
glNormal3fv(VertexNormals[x][z+1]);
glVertex3fv(Triangles[x][z][j].Vertex[1]);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(Triangles[x][z][j].Vertex[2].u,
Triangles[x][z][j].Vertex[2].v);
glNormal3fv(VertexNormals[x+1][z+1]);
glVertex3fv(Triangles[x][z][j].Vertex[2]);
}
}
}
glEnd();

glEndList();

// Prepare fourth display list.

list4=list+3;
ListIndices[3] = list4;

glNewList(list4, GL_COMPILE);

FullTerrainTexture.bind();

glBegin(GL_TRIANGLES);
for(z = mapHeight-(mapHeight/4); z < mapHeight; z++)
{
for(int x = mapWidth-(mapWidth/4); x < mapWidth; x++)
{

for (int j=0; j<2; j++)
{
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(Triangles[x][z][j].Vertex[0].u,
Triangles[x][z][j].Vertex[0].v);
glNormal3fv(VertexNormals[x][z]);
glVertex3fv(Triangles[x][z][j].Vertex[0]);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(Triangles[x][z][j].Vertex[1].u,
Triangles[x][z][j].Vertex[1].v);
glNormal3fv(VertexNormals[x][z+1]);
glVertex3fv(Triangles[x][z][j].Vertex[1]);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(Triangles[x][z][j].Vertex[2].u,
Triangles[x][z][j].Vertex[2].v);
glNormal3fv(VertexNormals[x+1][z+1]);
glVertex3fv(Triangles[x][z][j].Vertex[2]);
}
}
}
glEnd();

glEndList();
}

If you want to make four display lists, you divide each side by two, not four which will lead to 16 displaylists if done properly.

You should build the four lists like this:

// list one
for(j=0; j<mapHeight/2; j++)
for(i=0; i<mapWidth/2; i++)

// list two
for(j=mapHeight/2; j<mapHeight; j++)
for(i=0; i<mapWidth/2; i++)

// list three
for(j=0; j<mapHeight/2; j++)
for(i=mapWidth/2; i<mapWidth; i++)

// list four
for(j=mapHeight/2; j<mapHeight; j++)
for(i=mapWidth/2; i<mapWidth; i++)

Take a paper, draw a square, and inside this square, draw the four squares you are building. And read the for-loops carefully when drawing them and you will surely understand why you only get diagonals.

hello…
yes i noticed that in the loops… i fixed it already!
thanks for the help!