1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for...
-
date post
21-Dec-2015 -
Category
Documents
-
view
236 -
download
0
Transcript of 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for...
1
Lecture 6
Attributes of graphical primitives
Colors
Colors in OpenGL
Algorithms for scan-conversion
2
Colors
It is difficult to explain colors: they should be experienced. Color is nothing more that wavelengths of light at a certain frequency. Actually, the human eye is only said to perceive a small fraction of the total light available. Certain lights called Gamma Rays, X-rays, and Ultraviolet lights are too low of a frequency for humans to see. Lights like Infrared, Microwaves, and Radio waves, are too high of a frequency for the human eye to see. Humans only see a small portion of light between these frequencies and we calls these lights color.
3
Colors
The color of an object is evident by the amount of light it reflects.
For example, a red apple reflects mostly red light, and absorbs mostly all other colors.
The color white is obtained when all colors are reflected off an object (no colors absorbed) giving the object appearance of white.
Black is the absorption of all colors. It is not considered as a color.
Black is considered the absence of color, and therefore is not allowed to join its color family.
4
Colors: RGB Model
There are different ways to choose color for your drawing.
The easiest and most powerful way is to use RGB color.
RGB color stands for Red, Green, and Blue, and is called additive color.
It is given this name because RGB starts with the absence of color, and then adds elements of red, green, and blue to achieve the desired color.
5
Colors: RGB Model
It is not possible to obtain all colors with RGB model, or with any other color model. RGB just matches a color as close as possible.
Usually there are 256 different values for each red, green, and blue. This also means that there are about 16.7 million different colors available (256*256*256 = 28 * 28 * 28).
Some systems and languages, such as OpenGL, uses a similar idea with RGB color, except that they may use numbers from 0.0 to 1.0.
Theoretically this means that there is an infinite amount of colors formed from RGB because there is an infinite amount of numbers between 0 and 1.
6
Colors
RGB model
7
Colors
RGB Color cube
8
Colors
CMY model
9
Colors
CMY cube
10
Colors
HSV model (hue, saturation, value): used by artists Called also HSL model (L-light)
Hue: the name that we give to a color: red, yellow, cyan, etc. Saturation: “how pure the color is”, that is how far is a hue from the same hue mixed with white so that the color has more pastel shade Value/Light - how bright the color appear
11
Colors
HSV model (hue, saturation, value)
12
Levels of Gray
Levels of gray/colors: instead of 0/1 more digits
13
Levels of Gray
Reducing the levels of gray: Original scanned picture
14
Levels of Gray
Reducing the levels of gray: Three bits per pixel
15
Levels of Gray
Reducing the levels of gray: One bit per pixel
16
Color palette
Color table (palette)
17
Colors in OpenGL
OpenGL uses RGB color model The values of red, green, and blue are numbers from 0.0 to 1.0.
18
Colors in OpenGL
The instruction glColor3f( float red, float green, float blue ) sets a color. The syntax is the same as in the sample program for drawing a triangle. Problem: Draw 5 triangles with different colors. Write the values of RGB and the color obtained.
19
Colors in OpenGL
Syntax of OpenGL instructions:
FunctionName2i or FunctionName3f
2 or 3 means number of parameters: 2 or 3 i - integer values, f- float values, d-double values.
All the following instructions will give the same color - red:
glColor1f( 1.0 ); glColor1d( 1.0 ); glColor4i( 1, 0, 0, 0 );
20
Colors in OpenGL
There is an optional fourth value in the color definition called the alpha value.
Alpha values are used for displaying different effects, e.g., blending, transparency, lighting and shadows.
OpenGL may interpolate different colors. Problem: Use the sample triangle program and
assign different colors for each vertex. Describe the result.
21
Colors in OpenGL
glBegin( GL_TRIANGLES ); // Begin a triangle
glColor3f( 1.0, 0.0, 0.0 ); // Red color
glVertex3f( 0.25, 0.25, 0.0 );
glColor3f( 0.0, 1.0, 0.0 ); // Green color
glVertex3f( 0.75, 0.25, 0.0 );
glColor3f( 0.0, 0.0, 1.0 ); // Blue color
glVertex3f( 0.75, 0.75, 0.0 );
glEnd(); // End the triangle
22
Scan-Conversion
23
Triangle Scan-Conversion
24
Simple Algorithm
25
Inside Triangle Test
26
Inside Triangle Test
27
Triangle Sweep-Line Algorithm
28
Triangle Sweep-Line Algorithm
29
Polygon Scan Conversion
30
Inside Polygon Rule
31
Polygon Sweep-Line Algorithm
32
Polygon Sweep-Line Algorithm
33
FloodFill Algorithm
34
Scan Conversion of Polygons: Hardware Conversion