Computer Graphics (iii) _ Elements of attributes _3_opengl color function (top)

Source: Internet
Author: User
Tags new set

OpenGL color function (top)
Set the color display model to RGB:
Glutinitdisplaymode (Glut_single | GLUT_RGB);
the first parameter in the variable table indicates that a single frame cache is being used, and the second parameter sets the RGB mode, which is the default mode. We can use one of Glut_rgb or Glut_rgba to select a color model. If you want to specify a color with an index that points to a color table, replace Glut_rgb with OpenGL constant Glut_index.
OpenGL RGB and RGBA color models
Most OpenGL primitives use the RGB mode ( RGB Mode), which is associated with the RGBA mode ( RGBA Mode) are basically the same. the only difference between RGB and RGBA is whether the alpha value is being used in color blending. When you specify a special set of colors for an entity, the color state of OpenGL is defined ( Color State). The current color is used for subsequent entities defined until the color setting is changed again. A new set of colors affects only the objects that are defined later.
in RGB mode, we specify the red, green, and blue components of a color. The fourth color component is the alpha factor . (alpha coefficient)is optional, and the four-dimensional color description is called the RGBA color. The fourth color parameter is used to control color blending when the elements overlap. An important application of color blending is the simulation of transparency effects. In such calculations, the value of alpha corresponds to the transparency (or opacity) setting. In RGB (or RGBA) mode, use the following function to select the current color component:
glcolor* (colorcomponents);
The suffix code is the same as in the Glvertex function. Specify either RGB or RGBA mode with a data type code of 3 or 4 and a numeric value together with an optional vector suffix. The numeric data type is b (bytes), I (integer), s (short integer), f (floating point), and D (double-precision floating-point number), and unsigned values. The color component's floating-point number ranges from 0.0 to 1.0,glcolor the default color component that includes the alpha value is (1.0, 1.0, 1.0, 1.0), which sets the RGB color to white and the alpha value to 1.0. As an example, the following statement uses floating-point values in RGB mode to set the current color of the entity to cyan (the highest intensity blend of green and blue).
glcolor3f (0.0, 1.0, 1.0);
To specify three color components using an array, you can set the colors in the previous example as follows:
GLCOLOR3FV (Colorarray);
Use the Glbegin/glend function to set the OpenGL color that can be selected for a single point position.
the integer description of the color component depends on the performance of the system. Integer values for full-color systems of 8 bits per pixel (256 levels per component) range from 0 to 255. The corresponding color component floating-point number is 0.0, 1.0/255.0, 2.0/255.0, ... 255.0/255.0 = 1.0. In a full-color system, we can specify the cyan component with an integer value:
Glcolor3i (0, 255, 255);
the frame cache actually stores integer values, so specifying color components with integers avoids the conversion work that the floating-point numbers must make. Any format specifies a color value that is scaled to an integer in the range determined by a particular system's significant bit.

OpenGL Color Index Mode
You can also specify a color using the color index pattern that points to the color table in OpenGL. In this mode, the current color is set by specifying an index to the color table:
glindex* (ColorIndex);
The parameter ColorIndex is given a non-negative integer. The index value is stored in the frame cache location corresponding to the entity that is subsequently specified. We can specify the index as the following data type: unsigned bytes, integers, and floating-point numbers. The data type of the parameter ColorIndex is specified by the suffix code UB, S, I, D, and F, and the index number of the color table is always 2, such as 256 or 1024. The number of bits per table item depends on the hardware facilities of the system. As the color of the index pattern specifies the example, the following statement sets the current color index to 196.
Glindexi (196);
all elements defined after this statement are given a color stored in the position of the color table until the current color changes again.
there is no function to load a color lookup table in the OpenGL core library because the table processing subroutine is part of the window System. Some window systems support multiple color tables, while others have only one color table and a limited selection. However, there is a glut subroutine that can be used to interact with the windowing system to specify the color for a given index position:
Glutsetcolor (index, red, green, blue);
color Parameters red, green and blue are given floating-point numbers in the range from 0.0 to 1.0. The color is loaded into the table item specified with the value of the parameter index.
The OpenGL Core Library expands the subroutines that process the other three color tables. They are part of the OpenGL Imaging subset (Imaging subset). The color values that exist in these tables can be processed by individual caches to be used to modify pixel values. examples of using these tables are setting the focus of the camera, filtering out certain colors from the image, enhancing some intensity or adjusting the brightness, converting grayscale photos to color, and displaying anti-aliasing. These tables can be used to change the color model, changing the RGB color to a color description using another three "base colors" such as cyan, magenta, and yellow.
OpenGL Imaging Sub-set using gl_color_table, gl_post_convolution_color_table or gl_post_color_matrix_color_table The specific color table for the name is activated with the glenable function. We can use sub-programs in the imaging sub-set to select a specific color table, set the value of the color table, copy the value of the table, or specify which component needs to change the color of the pixel and how to change it.

OpenGL Color Blending
in many applications, it is easy to mix the colors of overlapping objects or reconcile an object with the background. Examples of this are simulated brush effects, mixing two or more photos into one, transparency effect modeling, and anti-aliasing of objects in the scene. Many graphics packages provide methods for generating a variety of color-blending effects called color-harmonic functions ( color-blendingfunction) or image blending functions ( image-compositing function )。 In OpenGL, two object colors are reconciled by first loading the first object into the frame cache and then mixing the color of the second object with the frame cache color. The current frame cache color is called the OpenGL target color ( destinationcolor), and the color of the second object is called the OpenGL source color (source colour). The Reconcile method is only done in RGB or RGBA mode.  To color reconcile in your app, you must first activate the OpenGL feature with the following function.
Glenable (Gl_blend);
use the following function to turn off OpenGL's color blending subroutine:
  Gldiaable (Gl_ BLEND);
if color blending is not activated, the color of an object will simply replace the contents of the corresponding position in the frame cache.
colors can be reconciled to the effect you want to achieve by specifying two sets of harmonic factors to produce different color effects. A set of tuningand factors against the current object in the frame cache (the "target object"), and the other set of harmonic factors against the new ("source") object. Will beThe new harmonic color to install the human frame cache is calculated as follows:

here, the RGBA source color component is (rs,gs,bs,as), the target color component is (RD,GD,BD,AD), the source harmonic factor is (SR,SG,SB,SA), and the target harmonic factor is (DR,DG,DB,DA). the calculated combinations of color components are grouped into one to 0.0 to 1.0. That is, any sum greater than 1.0 is set to 1.0, and any less than 0.0 and set to 0.0.
use the following functions to select the values of the harmonic factor:
G1blendfunc (Sfactor,dfactor);
The parameters Sfactor and Dfactor, the source and target factors, are assigned values with OpenGL symbolic constants to specify a predefined set of four element harmonic coefficients. For example, the constant Gl_zero represents a harmonic factor (0.0, 0.0, 0.0, 0.0) and Gl_one is represented (1.0, 1.0, 1.0, 1.0). We can use Gl_dst_alpha or Gl_src_alpha to set the four harmonic factors to the target alpha value or the source alpha value. Other OpenGL constants that can be used to set the harmonic factor are gl_one_minus_dst_alpha,
Gl_one_minus_src_alpha,gl_dst_color and Gl_src_color. These harmonic factors are often used to simulate transparency, which is discussed in detail in section 10.19. The default value for Sfactor is Gl_one, and the default value for Dfactor is Gl_zero. Therefore, the default values for these two sets of harmonic factors will cause the new color value to replace the current color value in the frame cache.
additional functions included in the OpenGL expansion library are called imaging subsets. These subroutines contain subroutines that set the harmonic color and the subroutines that specify the harmonic equation.

Computer Graphics (iii) _ Elements of attributes _3_opengl color function (top)

Related Article

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.