OpenGL allows you to specify different colors for different vertices of the same polygon. For example:
# Include <math. h>
Const GLdouble Pi = 3.1415926536;
Void myDisplay (void)
{
Int I;
// GlShadeModel (GL_FLAT );
GlClear (GL_COLOR_BUFFER_BIT );
GlBegin (GL_TRIANGLE_FAN );
GlColor3f (1.0f, 1.0f, 1.0f );
GlVertex2f (0.0f, 0.0f );
For (I = 0; I <= 8; ++ I)
{
GlColor3f (I & 0x04, I & 0x02, I & 0x01 );
GlVertex2f (cos (I * Pi/4), sin (I * Pi/4 ));
}
GlEnd ();
GlFlush ();
}
By default, OpenGL calculates other vertices between two vertices and fills them with "appropriate" Colors to bring the color values of adjacent points closer. If the RGB mode is used, the gradient effect will appear. If the color index mode is used, the index values of neighboring points are close. If the items in the color table are set to close colors, the gradient effect will appear. However, if the color of the item in the color table is very different, it may seem very strange.
You can use the glShadeModel function to disable this calculation. If the color of the vertex is different, set all other vertices between the vertex to be the same as a vertex. (The Color of the vertex specified after the straight line prevails, and the polygon will be subject to the color of any vertex, which is determined by implementation .) To avoid this uncertainty, try to use the same color in the polygon.
How to Use glShadeModel:
GlShadeModel (GL_SMOOTH); // smooth mode, which is also the default mode
GlShadeModel (GL_FLAT); // monochrome mode