View Full Version : Interpolated Polygon Colors?

07-19-2000, 08:56 AM

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.


07-19-2000, 09:38 AM
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:

glColor3f(....); // color for vertex 1
glVertex3f(....); // vertex 1
glColor3f(....); // color for vertex 2
glVertex3f(....); // vertex 2
glColor3f(....); // color for vertex 3
glVertex3f(....); // vertex 3

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.

07-20-2000, 05:51 AM
Thanks that worked and looks great too!

Where can I find example source on vertex arrays?


07-20-2000, 06:30 AM
You might want to take a look at NeHe's tutorials (http://nehe.gamedev.net/opengl.asp) , 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 (http://www.gamasutra.com) .