Height field Question?

I have written a small app that imports height data and constructs a quadstrip height field, I colour all quads green(grass).

I wish to shade the terrain according to elevation(ie highest light green, lowest dark green).

I managed this once before using lighting, I entered the vertices coords as the normals then did something daft with the lighting and it worked although it was flat shaded. I can not seem to recreate this.

I have tried another approach using colours for each vertex instead of lighting, but there is a horrible banding which matches horizontally but not vertically(this is probaly because I am drawing a quadstrip across, then dropping directly down and drawing another until the height field is drawn.)

does anyone know where I can get some examples, or can help

Thanx.

Paul Sharp

Ok here is a long post, I think

If you read the NEHE tutorials this should be a walk in the park.

Set up OpenGL like you normaly would.

Now load your data. Find the highest point and lowest point. (You can figure that out right?)

Now forgive me if this math is crude or the data types are wrong. I am makeing it up as I go. ps, I assume the lowest point is 0. If they aren’t you will have to translate them up to 0 before you try this equation (or else bill gates will infest your computer, JK).

For Each Point Do this:

fColorofPoint = fPoint*((fMaxpoint+1.0f)/(fMinpoint+1.0f)); //Make sure minpoint is aleast 1 or you get a math error.
glColor3f( 0.0f, fColorofPoint, 0.0f); //Set point color.

Ok, here are the notes on this code.

First of all the lowest points will be such a dark green it will look black.

fPoint is the height of the point you want to get the color for.

fMaxpoint is the height of the highest point.

fMinpoint is the height of the lowest point.

You must compute this data for each point.

Opengl will transition the color between 2 points. That way a bright green area will smoothly transition into a darker one.

Hope I helped!

Galileo430

It doesnt work!

elevations that are at or very close to 0 are coloured black, all the rest are coloured green.

for(int i = 0; i < m_arVertices.GetSize(); i++)
{
float fHeight = m_arVertices[i].y;
float fColorofPoint = fHeight*( (15.0f + 1.0f) / (0.0f + 1.0f));
m_arVertices[i].m_Red = 0.0f;
m_arVertices[i].m_Green = fColorofPoint;
m_arVertices[i].m_Blue = 0.0f;

	}

I use 15 as that is the heighest elev.

Originally posted by ironduke:

float fColorofPoint = fHeight*( (15.0f + 1.0f) / (0.0f + 1.0f));
I use 15 as that is the heighest elev.

If you use glColorf(), the color range is 0.-1.; anything brighter will just be clamped. Set fColorofPoint to fHeight/15. and see if that doesn’t work better.

what should I use instead of colorf?

Originally posted by ironduke:
what should I use instead of colorf?

you should rescale the values within the [0,1] value range
(divide by the max value)

using glcolorub works.

Are you using Smooth shading?