Informationsteknologi Todays class Graphics programming n Color n

  • Slides: 30
Download presentation
Informationsteknologi Today’s class Graphics programming n Color n Monday, October 29, 2007 Computer Graphics

Informationsteknologi Today’s class Graphics programming n Color n Monday, October 29, 2007 Computer Graphics - Class 2 1

Informationsteknologi testline. c Example program testline. c shows the general structure of an Open.

Informationsteknologi testline. c Example program testline. c shows the general structure of an Open. GL program n Note the use of a callback function for the display n Monday, October 29, 2007 Computer Graphics - Class 2 2

Informationsteknologi Overview of image generation Scene – collection of objects in space n Viewer

Informationsteknologi Overview of image generation Scene – collection of objects in space n Viewer – forms image from objects n Light – illuminates the objects and helps visualize their textures n All of these need to be modeled to generate an appropriate image n Monday, October 29, 2007 Computer Graphics - Class 2 3

Informationsteknologi Coordinate systems World coordinates - the application’s coordinate system n Device coordinates -

Informationsteknologi Coordinate systems World coordinates - the application’s coordinate system n Device coordinates - the graphics device coordinate system, usually first quadrant n Normalized device coordinates - (0, 0) (x, y) (1, 1) n Monday, October 29, 2007 Computer Graphics - Class 2 4

Informationsteknologi Output primitives n The basic building blocks of graphics images: ® points ®

Informationsteknologi Output primitives n The basic building blocks of graphics images: ® points ® lines ® polygons ® circles ® character Monday, October 29, 2007 strings Computer Graphics - Class 2 5

Informationsteknologi Attributes n Properties of output primitives: ® intensity ® color ® line style

Informationsteknologi Attributes n Properties of output primitives: ® intensity ® color ® line style ® text style ® area-filling patterns Monday, October 29, 2007 Computer Graphics - Class 2 6

Informationsteknologi Open. GL geometry n n Specified by edges and vertices Vertices a sequence

Informationsteknologi Open. GL geometry n n Specified by edges and vertices Vertices a sequence or array of coordinates ® specified with 2, 3, or 4 (homogeneous) coordinates in short, int, float, or double types ® routines are gl. Vertex{234}{sifd}[v]() ® n Edges are determined by the order the vertices are entered Monday, October 29, 2007 Computer Graphics - Class 2 7

Informationsteknologi Open. GL geometry (cont. ) n n Vertices are specified between gl. Begin()

Informationsteknologi Open. GL geometry (cont. ) n n Vertices are specified between gl. Begin() and gl. End() Parameter to gl. Begin() describes type of geometry: GL_POINTS - a disconnected set of points ® GL_LINES - n/2 line segments ® GL_LINE_STRIP - n-1 line segments connected end to end ® GL_LINE_LOOP - n line segments connected end to end and last to first ® Monday, October 29, 2007 Computer Graphics - Class 2 8

Informationsteknologi Open. GL geometry (cont. ) n More parameters to gl. Begin(): - n/3

Informationsteknologi Open. GL geometry (cont. ) n More parameters to gl. Begin(): - n/3 triangles ® GL_TRIANGLE_STRIP - n-2 triangles ® GL_TRIANGLES § for even i (0, 2, 4, …) vertices i, i+1, i+2 define the triangle § for odd i (1, 3, 5, …) vertices i+1, i, i+2 define the triangle ® GL_TRIANGLE_FAN - n-2 triangles § vertices 0, i+1, i+2 define the triangles Monday, October 29, 2007 Computer Graphics - Class 2 9

Informationsteknologi Open. GL geometry (cont. ) n More parameters to gl. Begin(): - n/4

Informationsteknologi Open. GL geometry (cont. ) n More parameters to gl. Begin(): - n/4 quadrilaterals ® GL_QUAD_STRIP - n/2 -1 quadrilaterals ® GL_QUADS § vertices 2 i, 2 i+1, 2 i+3, 2 i+2 define the quadrilateral ® GL_POLYGON Monday, October 29, 2007 - a single convex polygon Computer Graphics - Class 2 10

Informationsteknologi Example program n Program brownian. c is an example of Open. GL and

Informationsteknologi Example program n Program brownian. c is an example of Open. GL and GLUT Monday, October 29, 2007 Computer Graphics - Class 2 11

Informationsteknologi In class exercise The picture below shows the first step in generating the

Informationsteknologi In class exercise The picture below shows the first step in generating the Koch curve, a famous fractal n Write an Open. GL code fragment to draw the image on the right n Monday, October 29, 2007 Computer Graphics - Class 2 12

Color

Color

Informationsteknologi Color characterization n n Colors are combinations of wavelengths of light Characterized by

Informationsteknologi Color characterization n n Colors are combinations of wavelengths of light Characterized by a function, C( ), which represents the strength of each wavelength of visible light present in the color To accurately produce a color on the CRT would require representation of each wavelength present in the color Impossible to do, and really does not represent how our eyes perceive color Monday, October 29, 2007 Computer Graphics - Class 2 14

Informationsteknologi Cones Color receptors in our eyes are called cones n Come in three

Informationsteknologi Cones Color receptors in our eyes are called cones n Come in three types n Each type has its own sensitivity curve, which represents how sensitive it is to the different wavelengths of light n Monday, October 29, 2007 Computer Graphics - Class 2 15

Informationsteknologi Tristimulus values n When cone i is exposed to a color distribution C(

Informationsteknologi Tristimulus values n When cone i is exposed to a color distribution C( ) it sends the brain a “number” which represents the total response of that cone to the color: n Thus, there are 3 numbers (one for each cone) that are sent to the brain to represent a color These are known as the tristimulus values The brain sums these numbers n n Monday, October 29, 2007 Computer Graphics - Class 2 16

Informationsteknologi CRT color model Applying the tristimulus approach to a CRT we have 3

Informationsteknologi CRT color model Applying the tristimulus approach to a CRT we have 3 color guns (R, G, B) n Each gun’s intensity is weighted by the appropriate tristimulus value to produce an overall color n Note that this is an additive system n Monday, October 29, 2007 Computer Graphics - Class 2 17

Informationsteknologi RGB color model Most common n Defined on a unit cube n Black

Informationsteknologi RGB color model Most common n Defined on a unit cube n Black at (0, 0, 0), white at (1, 1, 1) n Diagonally opposite colors are complementary (two colors added together give white; e. g. yellow (1, 1, 0) + blue (0, 0, 1)) n (R, G, B) = (1, 1, 1) - (C, M, Y) n Monday, October 29, 2007 Computer Graphics - Class 2 18

Informationsteknologi Color in Open. GL n Two models ® RGBA § A indicates opacity

Informationsteknologi Color in Open. GL n Two models ® RGBA § A indicates opacity • a value of 1. 0 indicates an opaque color • a value of 0. 0 indicates a transparent color § RGB is the same as RGBA with A set to 1. 0 § This is the internal form used in Open. GL’s state ® Color index § An index into a table of RGB values § Requires interaction with the windowing system Monday, October 29, 2007 Computer Graphics - Class 2 19

Informationsteknologi Color on paper For printing on paper, a complementary approach is needed since

Informationsteknologi Color on paper For printing on paper, a complementary approach is needed since you start with white paper (the presence of all color) n A subtractive system is needed, such that when you place all 3 primary colors down you get black n The standard subtractive system is CMY (cyan, magenta, yellow) n Monday, October 29, 2007 Computer Graphics - Class 2 20

HLS Informationsteknologi n n n Monday, October 29, 2007 A distortion of the RGB

HLS Informationsteknologi n n n Monday, October 29, 2007 A distortion of the RGB cube A double cone Hue is location of the dominant wavelength in the color (measured as angle from 0° (red) Lightness is measured from 0 to 1 vertically Saturation is the radial distance from the lightness axis, also 0 to 1 Computer Graphics - Class 2 21

Informationsteknologi Color angles Red = 0° n Yellow = 60° n Green = 120°

Informationsteknologi Color angles Red = 0° n Yellow = 60° n Green = 120° n Cyan = 180° n Blue = 240° n Magenta = 300° n Monday, October 29, 2007 Computer Graphics - Class 2 22

Informationsteknologi HSV n n n A single cone Hue and saturation the same as

Informationsteknologi HSV n n n A single cone Hue and saturation the same as HLS Value is captured in the vertical axis, also on a 0 to 1 scale Monday, October 29, 2007 Computer Graphics - Class 2 23

Informationsteknologi HSV to RGB conversion n n n n If H = 360 then

Informationsteknologi HSV to RGB conversion n n n n If H = 360 then H = 0 H = H / 60 I = floor (H) F=H-I P 1 = V * (1 - S) P 2 = V * (1 - S * F) P 3 = V * (1 - (S * (1 - F))) Case I of ® ® ® 0: R = V; G = P 3; B = P 1 1: R = P 2; G = V; B = P 1 2: R = P 1; G = V; B = P 3 3: R = P 1; G = P 2; B = V 4: R = P 3; G = P 1; B = V 5: R = V; G = P 1; B = P 2 Monday, October 29, 2007 Computer Graphics - Class 2 24

Informationsteknologi Programming the color lookup table In Open. GL a float is used for

Informationsteknologi Programming the color lookup table In Open. GL a float is used for the red, green, and blue components n One approach is to equally space the colors at some fixed L and S on the HLS model n Another approach is to determine the range of red, green, and blue in the image and quantize on three axes n Monday, October 29, 2007 Computer Graphics - Class 2 25

Informationsteknologi Index color mode GLUT_INDEX is used for the display mode n glut. Set.

Informationsteknologi Index color mode GLUT_INDEX is used for the display mode n glut. Set. Color(index, r, g, b) enters a color map entry n gl. Indexi(index) chooses a color map entry for the current color n gl. Clear. Index(index) sets the clear color for a window in index mode n Monday, October 29, 2007 Computer Graphics - Class 2 26

Informationsteknologi Default colors n n n n 0 = black 1 = red 2

Informationsteknologi Default colors n n n n 0 = black 1 = red 2 = green 3 = yellow 4 = blue 5 = magenta 6 = cyan 7 = white Monday, October 29, 2007 Computer Graphics - Class 2 27

Informationsteknologi Color index mode on PCs 8 bit planes n 256 entries in color

Informationsteknologi Color index mode on PCs 8 bit planes n 256 entries in color index n Need to be in 256 -color mode n Avoid setting colors 0 -7 n Monday, October 29, 2007 Computer Graphics - Class 2 28

Informationsteknologi Unix machines n SGI machines ® 12 bit planes ® avoid setting colors

Informationsteknologi Unix machines n SGI machines ® 12 bit planes ® avoid setting colors 0 -255 n Sun workstations ® 8 bit planes ® no default colors Monday, October 29, 2007 Computer Graphics - Class 2 29

Informationsteknologi Example program Program color. Map. cpp shows using the color map and indexed

Informationsteknologi Example program Program color. Map. cpp shows using the color map and indexed color n A large list of colors and their RGB values has been posted on the Example Programs page of the course website n Monday, October 29, 2007 Computer Graphics - Class 2 30