I was thinking of creating a 2×2 array with randomly generated values which then be drawn using glVertex3i, for example:
glBegin(GL_POLYGON);
int x = 5;
int z = 5;
for (int i=0; i<width; i++)
{
for (int j=0; j<height; j++)
{
glVertex3i(x, heightmap[i][j], z);
}
x -= 0.5;
z -= 0.5;
}
glEnd();
The only problem I’m having is that, the map isn’t drawn on the z dimension I think, because all I get is 1 side essentially.
What might be wrong? Obviously the algorithm is basic for now, but its just a starting point.
Let’s start here:
A polygon is required to be planar. All of the vertices must lie in a single plane. If they don’t, then OpenGL is not responsible for how it gets rendered. You cannot draw a heightmap as a single polygon and expect to get reasonable results. You must draw triangles, either with a series of
GL_TRIANGLE_STRIPs or withGL_TRIANGLES.Then, there’s what Christian said.