Here is my program abt the client state vertex (Thx for helping me, as it is quite urgent and I am of deeply frustration…)
In the Init() part, I called InitializeArray().
And this is the Initialize Array() code:
void InitializeArrays()
{
// used to track current entry in the index array
int index = 0;
int currentVertex;
// loop over all vertices in the terrain map
for (int z = 0; z < MAP_SIZE; z++)
{
for (int x = 0; x < MAP_SIZE; x++)
{
// set the values in the texture coordinate array. since the texture
// is tiled over each "square", we can use texture wrapping
g_texcoordArray[currentVertex][0] = (float) x;
g_texcoordArray[currentVertex][1] = (float) z;
}
}
for (z = 0; z < MAP_SIZE - 1; z++)
{
for (int x = 0; x < MAP_SIZE; x++)
{
currentVertex = z * MAP_SIZE + x;
g_indexArray[index++] = currentVertex + MAP_SIZE;
g_indexArray[index++] = currentVertex;
}
}
// enable the vertex arrays being used
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// pass the pointers to OpenGL
glVertexPointer(3, GL_FLOAT, 0, g_terrain);
glTexCoordPointer(2, GL_FLOAT, 0, g_texcoordArray);
}
And I get the g_terrain data in this way:
for(int z=0; z< MAP_SIZE; ++z)
{
for(int x=0; x< MAP_SIZE; ++x)
{
g_terrain[x+MAP_SIZEz][0]=float(x);
g_terrain[x+MAP_SIZEz][1]=float(Height(pHeightMap, x, z ));
g_terrain[x+MAP_SIZE*z][2]=float(z);
}
}
And in the displayscene() which is going to be called every frame, I have the code:
glVertexPointer(3, GL_FLOAT, 0, g_terrain);
glTexCoordPointer(2, GL_FLOAT, 0, g_texcoordArray);
for (int z = 0; z < MAP_SIZE-1; z++)
{
glDrawElements(GL_TRIANGLE_STRIP, MAP_SIZE * 2, GL_UNSIGNED_INT, &g_indexArray[z * MAP_SIZE * 2]);
}
I sincerely express my gratitude for your hlep…really thx