wow

01-09-2004, 09:42 PM

Hi all, the following is my code abt initializing a display list (which is aimed to render a 1024x12024 terrain ) Would anyone be kind enough to tell me if there is anything wrong in the function? Since I can't get any improvment after implementing the display list... Thx for your kindful help

void InitializeList(BYTE *pHeightMap)

{

g_terrainList = glGenLists(1);

int X = 0, Y = 0; // Create some variables to walk the array with.

int x, y, z; // Create some variables for readability

bool bSwitchSides = false;

if(!pHeightMap) return; // ensure height data is valid

glNewList(g_terrainList, GL_COMPILE);

glBindTexture(GL_TEXTURE_2D, g_Texture[0]);

glBegin( GL_TRIANGLE_STRIP );

for ( X = 0; X <= MAP_SIZE; X += STEP_SIZE )

{

// Chechk if we need to render the opposite way for this column

if(bSwitchSides)

{

// Render a column of the terrain, for this current X.

// We start at MAP_SIZE and render down to 0.

for ( Y = MAP_SIZE; Y >= 0; Y -= STEP_SIZE )

{

// Get the (X, Y, Z) value for the bottom left vertex

x = X;

y = Height(pHeightMap, X, Y );

z = Y;

// Set the current texture coordinate and render the vertex

SetTextureCoord( (float)x, (float)z );

glVertex3i(x, y, z);

// Get the (X, Y, Z) value for the bottom right vertex

x = X + STEP_SIZE;

y = Height(pHeightMap, X + STEP_SIZE, Y );

z = Y;

// Set the current texture coordinate and render the vertex

SetTextureCoord( (float)x, (float)z );

glVertex3i(x, y, z);

}

}

else

{

// Render a column of the terrain, for this current X.

// We start at 0 and render down up to MAP_SIZE.

for ( Y = 0; Y <= MAP_SIZE; Y += STEP_SIZE )

{

// Get the (X, Y, Z) value for the bottom right vertex

x = X + STEP_SIZE;

y = Height(pHeightMap, X + STEP_SIZE, Y );

z = Y;

// Set the current texture coordinate and render the vertex

SetTextureCoord( (float)x, (float)z );

glVertex3i(x, y, z);

// Get the (X, Y, Z) value for the bottom left vertex

x = X;

y = Height(pHeightMap, X, Y );

z = Y;

// Set the current texture coordinate and render the vertex

SetTextureCoord( (float)x, (float)z );

glVertex3i(x, y, z);

}

}

// Switch the direction the column renders to allow the fluid tri strips

bSwitchSides = !bSwitchSides;

}

// Stop rendering triangle strips

glEnd();

glEndList();

}

void InitializeList(BYTE *pHeightMap)

{

g_terrainList = glGenLists(1);

int X = 0, Y = 0; // Create some variables to walk the array with.

int x, y, z; // Create some variables for readability

bool bSwitchSides = false;

if(!pHeightMap) return; // ensure height data is valid

glNewList(g_terrainList, GL_COMPILE);

glBindTexture(GL_TEXTURE_2D, g_Texture[0]);

glBegin( GL_TRIANGLE_STRIP );

for ( X = 0; X <= MAP_SIZE; X += STEP_SIZE )

{

// Chechk if we need to render the opposite way for this column

if(bSwitchSides)

{

// Render a column of the terrain, for this current X.

// We start at MAP_SIZE and render down to 0.

for ( Y = MAP_SIZE; Y >= 0; Y -= STEP_SIZE )

{

// Get the (X, Y, Z) value for the bottom left vertex

x = X;

y = Height(pHeightMap, X, Y );

z = Y;

// Set the current texture coordinate and render the vertex

SetTextureCoord( (float)x, (float)z );

glVertex3i(x, y, z);

// Get the (X, Y, Z) value for the bottom right vertex

x = X + STEP_SIZE;

y = Height(pHeightMap, X + STEP_SIZE, Y );

z = Y;

// Set the current texture coordinate and render the vertex

SetTextureCoord( (float)x, (float)z );

glVertex3i(x, y, z);

}

}

else

{

// Render a column of the terrain, for this current X.

// We start at 0 and render down up to MAP_SIZE.

for ( Y = 0; Y <= MAP_SIZE; Y += STEP_SIZE )

{

// Get the (X, Y, Z) value for the bottom right vertex

x = X + STEP_SIZE;

y = Height(pHeightMap, X + STEP_SIZE, Y );

z = Y;

// Set the current texture coordinate and render the vertex

SetTextureCoord( (float)x, (float)z );

glVertex3i(x, y, z);

// Get the (X, Y, Z) value for the bottom left vertex

x = X;

y = Height(pHeightMap, X, Y );

z = Y;

// Set the current texture coordinate and render the vertex

SetTextureCoord( (float)x, (float)z );

glVertex3i(x, y, z);

}

}

// Switch the direction the column renders to allow the fluid tri strips

bSwitchSides = !bSwitchSides;

}

// Stop rendering triangle strips

glEnd();

glEndList();

}