View Full Version : How to draw a polygon with varying color?
07-28-2003, 07:56 AM
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?
07-28-2003, 08:30 AM
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).]
07-28-2003, 11:22 AM
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?
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:
Check out the color tutorials at http://nehe.gamedev.net
07-28-2003, 12:34 PM
Thanks a lot!
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.