How to draw a polygon with varying color?

Hi! I want to draw a polygon and use varying on it to indicate different temperature on it. That means the color will change continusly.
How can I implement it? Do I need to use some function related to lighting or can avoid it?
Thank you!

I am going to assume that you know how to draw a polygon and add color to it. When you put a command like “glColor3f(1.0f,0.5f,0.5f)” you should instead create 3 GLfloat’s (ie GLfloat red, GLfloat Green, GLfloat Blue) and then instead put “glColor3f(Red,Green,Blue)” and at the end of your draw routine you can modify them, by adding to one variable or subtracting from another to get the desired effect, this way, every time through the draw routine the color will change.

[This message has been edited by GlutterFly (edited 07-28-2003).]

This method can make the polygon have different colors at different time. However, can I make the different points of polygon have different colors at the same time?
Thank you!

You can specify a new color for every vertex of the polygon. Colors are interpolated linearly between vertices. For example, one triangle with 3 different colors at the same time:

glBegin(GL_TRIANGLES);
glColor3f(1.0,0,0);
glVertex3f(1,0,0);

glColor3f(0,1.0,0);
glVertex3f(0,1,0);

glColor3f(0,0,1.0);
glVertex3f(0,0,1);
glEnd();

Check out the color tutorials at http://nehe.gamedev.net

Thanks a lot!