Opengl specifies the coloring model

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.