LongJumper
2003.10.07, 01:24 AM
I can't seem to control how large in width my heightfields are. Mostly because I'm having trouble grasping the way they are constructed. They are way too huge, but I want the greyscale image to be larger so that I can edit it a little better. So a 5x5 pixel image wouldn't be very easy to work on.
worldSize is whatever you want to set it to, although I notice huge problems with making it smaller than the dimensions of the greyscale image.
I'm also seeing a few stray strips occassionaly. What are some reasons why those would appear?
int mapZ = worldSize;
int mapX = worldSize;
for(int z = 0;z<mapZ;z++)
{
for(int x = 0;x<mapX;x++)
{
terrain[x][z][0] = float(x)*worldSize;
terrain[x][z][1] = (float)imageData[(z*mapZ+x)*3];
terrain[x][z][2] = -float(z)*worldSize;
}
}
terrainList = glGenLists(1);
glNewList(terrainList,GL_COMPILE);
glPushMatrix();
glBindTexture(GL_TEXTURE_2D,texture);
glFrontFace(GL_CW);
glBegin(GL_TRIANGLE_STRIP);
for(int z = 0;z<mapZ-1;z++)
{
for(int x = 0;x<mapX-1;x++)
{
glTexCoord2f(0,0);
glVertex3f(terrain[x][z][0],terrain[x][z][1],terrain[x][z][2]);
glTexCoord2f(10,0);
glVertex3f(terrain[x+1][z][0],terrain[x+1][z][1],terrain[x+1][z][2]);
glTexCoord2f(10,10);
glVertex3f(terrain[x][z+1][0],terrain[x][z+1][1],terrain[x][z+1][2]);
glTexCoord2f(0,10);
glVertex3f(terrain[x+1][z+1][0],terrain[x+1][z+1][1],terrain[x+1][z+1][2]);
}
}
glEnd();
glFrontFace(GL_CCW);
glPopMatrix();
glEndList();
worldSize is whatever you want to set it to, although I notice huge problems with making it smaller than the dimensions of the greyscale image.
I'm also seeing a few stray strips occassionaly. What are some reasons why those would appear?
int mapZ = worldSize;
int mapX = worldSize;
for(int z = 0;z<mapZ;z++)
{
for(int x = 0;x<mapX;x++)
{
terrain[x][z][0] = float(x)*worldSize;
terrain[x][z][1] = (float)imageData[(z*mapZ+x)*3];
terrain[x][z][2] = -float(z)*worldSize;
}
}
terrainList = glGenLists(1);
glNewList(terrainList,GL_COMPILE);
glPushMatrix();
glBindTexture(GL_TEXTURE_2D,texture);
glFrontFace(GL_CW);
glBegin(GL_TRIANGLE_STRIP);
for(int z = 0;z<mapZ-1;z++)
{
for(int x = 0;x<mapX-1;x++)
{
glTexCoord2f(0,0);
glVertex3f(terrain[x][z][0],terrain[x][z][1],terrain[x][z][2]);
glTexCoord2f(10,0);
glVertex3f(terrain[x+1][z][0],terrain[x+1][z][1],terrain[x+1][z][2]);
glTexCoord2f(10,10);
glVertex3f(terrain[x][z+1][0],terrain[x][z+1][1],terrain[x][z+1][2]);
glTexCoord2f(0,10);
glVertex3f(terrain[x+1][z+1][0],terrain[x+1][z+1][1],terrain[x+1][z+1][2]);
}
}
glEnd();
glFrontFace(GL_CCW);
glPopMatrix();
glEndList();