Color:
In
Rgba mode, each pixel holds the following data: R value (red component), G value (green component), B value (blue component), and a value (alpha component). Where red, green, and blue combinations of colors, we can get the various colors we need, and Alpha does not directly affect the color, it will be left to introduce later.
Choosing a color in RGBA mode is a simple thing to do with just one function. The
glcolor* series functions can be used to set the color, where versions of three parameters can specify values for R, G, B, and a for the default; The four-parameter versions can specify values for R, G, B, and a, respectively. For example:
void glcolor3f (Glfloat red, Glfloat Green, glfloat blue);
void glcolor4f (glfloat red, Glfloat Green, glfloat Blue, glfloat Alpha);
(remember?) 3f means there are three floating-point parameters ~ See the narrative of the glvertex* function in Lesson two.
uses floating-point numbers as parameters, where 0.0 means that the color is not used, and 1.0 means that the color is used up to a maximum. For example:
glcolor3f (1.0f, 0.0f, 0.0f); does not use green, blue, and red is the most used, resulting in the purest red.
glcolor3f (0.0f, 1.0f, 1.0f); Indicates the use of green, blue to the maximum, without using red. The effect of blending is light blue.
glcolor3f (0.5f, 0.5f, 0.5f); means half of the colors used and the effect is gray.
NOTE: Floating-point numbers can be accurate to several digits after the decimal point, which does not mean that the computer can display so many colors. In fact, the number of colors the computer can display is determined by the hardware. If OpenGL cannot find an exact color, it will be treated like rounding.
Note: The Glcolor series function, where the parameter type is not the same, means that the value of the "maximum" color is also different.
A function with a suffix of f and D, with 1.0 representing the maximum use.
A function that uses a suffix of B to represent the maximum use of 127.
A function that uses UB as a suffix, with 255 representing the maximum use.
A function that uses the S suffix to represent the maximum use of 32767.
A function that uses us as a suffix, with 65535 representing the maximum usage.
Specify a shading model
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 the other points between vertices of two points and fills them with "fit" colors so that the adjacent points have a similar color value. If you are using RGB mode, you will appear to have a gradient effect. If you are using the color index pattern, the index value of its neighboring points is close, and if you set the close item in the color table to a close color, it will appear to be the effect of the gradient. But if the color table is close to the color of the items is very large, it may seem strange effect.
You can use the Glshademodel function to turn off this calculation, and if the colors of the vertices are different, set all other points between the vertices to be the same as a point. (The color of the point specified later in the line is whichever, and the polygon is determined by the color of any vertex.) 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
Summary:
This lesson learns how to set a color. The RGB color method is the most common way of PC on the current computer.
You can set the color remaining on the screen after the glclear is cleared.
You can set the color Fill method: smooth or monochrome.
OpenGL Homemade API 3