I following a terrain tutorial right now, and I am having trouble with rendering it. The tutorial I am following, using allegroGL, to calculate the height in a heightmap. They use the function readpixel, to return the pixel level in a heightmap, and then it stores those values in a 2d array, like so:
for(x = 0; x < AREA_SIZE; x++)
{
for(y = 0; y < AREA_SIZE; y++)
{
h = (float) getpixel(height_bitmap, x, y); // [0..256]
h /=4.0; // scale down by factor
height_field[(int)x][(int)y] = h;
}
}
In my demo, I don't want to use getpixel, so I used the usual method of loading heightmaps:
HeightmapFile = fopen(filename, "rb");
fread(HeightmapData, 1, SIZE_X * SIZE_Y, HeightmapFile);
fclose(HeightmapFile);
Now the problem is, I am wanting to render the information from my 1 dimensional array, using triangle strips, like the tutorial does. First, I have to convert the single dimension array, to a 2 dimension array, for ease of access. This is my code for exchanging the data.
for(int p=0; p<SIZE_X; p++)
{
for(int q=0; q<SIZE_Y; q++)
{
HeightmapArray[p][q] = HeightmapData[p + (q*512)];
}
}
Now the code for rendering:
glBegin(GL_TRIANGLE_STRIP);
for(x = 0; x < SIZE_X-Step; x+=Step)
{
for(z = 0; z < SIZE_Y-Step; z+=Step)
{
glColor3f(0, Height(HeightmapData, x, z)/256.0, 0);
glVertex3f(Scale*(x+Step), Scale*HeightmapArray[x+Step][z], Scale*z);
glVertex3f(Scale*x, Scale*HeightmapArray[x][z], Scale*z);
}
}
glEnd();
I tried this method and it doesn't work. It has a general outline of the terrain, but there are blocky areas, and areas with lines crossing all over the terrain.
Any help is GREATLY appreciated.
[edited by - Orb on October 8, 2003 6:09:41 PM]