PDA

View Full Version : continous display lists to render a terrain! how?



worm
12-09-2000, 10:47 AM
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();
}

12-10-2000, 05:16 PM
That's because you're dividing the width in
4 pieces, and the height in 4 pieces,
resulting in 16 sub-pieces. However, you only
render display lists for four of them (the
ones on the diagonal).