Interpolated Polygon Colors?

Hi,

I wish to draw a terrain mesh, and the triangles must be smooth-colored by their altitudes.

For example, if the bottom of a tall triangle is blue, and the top red, there must be a gradual transition between blue and red in between.

Is there any way to do this? It’d be nice to specify the color of the verticies and then have the fill interpolated.

Thanks,
John

Uh, yep, OpenGL does this by default I believe. Just specify the color for each vertex and that’s it. glShadeModel sets the fill mode and is supposed to default to GL_SMOOTH. So for an immediate primitive do something like this:

glBegin(GL_TRIANGLES)
glColor3f(…); // color for vertex 1
glVertex3f(…); // vertex 1
glColor3f(…); // color for vertex 2
glVertex3f(…); // vertex 2
glColor3f(…); // color for vertex 3
glVertex3f(…); // vertex 3
glEnd();

That should do what you want although that’s not the best approach to use for a terrain renderer (using individual primitives I mean) instead look into strips and vertex arrays. Vertex arrays use a color array to specify color for each vertex in the vertex array.

Thanks that worked and looks great too!

Where can I find example source on vertex arrays?

John

You might want to take a look at NeHe’s tutorials , there might be something there that uses vertex arrays.
And as far as terrain renderers go, I know I just read about one recently on Gamasutra .