I am working on a project for school and part of it was making a height map.
I managed to create the height map as requested, but was hoping to go for a little extra credit and smooth the entire surface. Here's an image of what I have now:
http://img.photobucket.com/albums/v222/shavus/hMap.png
The code that I used to generate it was taking an input .jpg and then using GL_TRIANGLE_STRIP to create the map that I already have.
The code I used:
glBegin(GL_TRIANGLE_STRIP);
for(int i = 1; i <= sourceImage->ny; i++)
{
for(int j = 1; j <= sourceImage->nx; j++)
{
// Define Color for the Vertex
int red = PIC_PIXEL(sourceImage , j, i, 0); // Find RGB value for each pixel
int green = PIC_PIXEL(sourceImage , j, i, 1);
int blue = PIC_PIXEL(sourceImage , j, i, 2);
float color = (float)(red + green + blue)/(3.0*255.0);
// Define Position for the Vertex
float xPos = (-1.0 + 2.0*((float)j/(float)sourceImage->nx)) * boxSize;
float yPos = (-1.0 + 2.0*((float)i/(float)sourceImage->ny)) * boxSize;
float height = (-boxSize + 2*((red + green + blue) / (3.0 * 255.0)));
glColor3f(color, color, color);
height = height * 0.5 * boxSize;
glVertex3f(xPos, yPos, height);
}
}
glEnd();
How can I make this a smooth surface to look something more like this?
http://zac-interactive.dk/blogimages/heightmap.jpg
Thanks for any help you can provide!