views:

108

answers:

1
+1  Q: 

OpenGL Heightmap

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!

A: 

The easy way to get rid of sudden changes in elevation in your heightmap and thus make it smoother is to run a convolution filter over it.

Here is a link:

http://www.gamedev.net/reference/articles/article2164.asp

on doing the box filter. It's not the best filter you can use but it will make a big difference.

Jose