Transcript
Page 1: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

1

Lecture 6

Attributes of graphical primitives

Colors

Colors in OpenGL

Algorithms for scan-conversion

Page 2: 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.

Page 3: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

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.

Page 4: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

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.

Page 5: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

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.

Page 6: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

6

Colors

RGB model

Page 7: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

7

Colors

RGB Color cube

Page 8: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

8

Colors

CMY model

Page 9: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

9

Colors

CMY cube

Page 10: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

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

Page 11: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

11

Colors

HSV model (hue, saturation, value)

Page 12: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

12

Levels of Gray

Levels of gray/colors: instead of 0/1 more digits

Page 13: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

13

Levels of Gray

Reducing the levels of gray: Original scanned picture

Page 14: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

14

Levels of Gray

Reducing the levels of gray: Three bits per pixel

Page 15: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

15

Levels of Gray

Reducing the levels of gray: One bit per pixel

Page 16: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

16

Color palette

Color table (palette)

Page 17: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

17

Colors in OpenGL

OpenGL uses RGB color model The values of red, green, and blue are numbers from 0.0 to 1.0.

Page 18: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

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.

Page 19: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

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 );

Page 20: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

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.

Page 21: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

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

Page 22: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

22

Scan-Conversion

Page 23: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

23

Triangle Scan-Conversion

Page 24: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

24

Simple Algorithm

Page 25: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

25

Inside Triangle Test

Page 26: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

26

Inside Triangle Test

Page 27: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

27

Triangle Sweep-Line Algorithm

Page 28: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

28

Triangle Sweep-Line Algorithm

Page 29: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

29

Polygon Scan Conversion

Page 30: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

30

Inside Polygon Rule

Page 31: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

31

Polygon Sweep-Line Algorithm

Page 32: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

32

Polygon Sweep-Line Algorithm

Page 33: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

33

FloodFill Algorithm

Page 34: 1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion

34

Scan Conversion of Polygons: Hardware Conversion


Recommended