1 / 14

Color

Color. Open GL Chapter 4. The goal of almost all OpenGL applications is to draw color pictures in a window on the screen. Thus in a sense, the point of all the calculations performed by OpenGL commands is to determine the final color of every pixel that is to be drawn in the window.

ruby
Download Presentation

Color

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Color Open GL Chapter 4 Chapter 4 -- Color

  2. The goal of almost all OpenGL applications is to draw color pictures in a window on the screen. • Thus in a sense, the point of all the calculations performed by OpenGL commands is to determine the final color of every pixel that is to be drawn in the window. • This chapter explains the commands for specifying colors and how OpenGL interprets them. Chapter 4 -- Color

  3. Color Perception • Practically light is composed of photons - each traveling along its own path, and each vibrating at its own frequency (or wavelength, or energy) • wavelengths ranging from about 390 nm (violet) and 720 nm (red) cover the colors of the visible spectrum. Chapter 4 -- Color

  4. The human eye perceives color when certain cells in the retina (called cone cells) become excited after being struck by photons. • The three different kinds of cone cells respond best to three different wavelengths of light: One type responds to red, one to blue, and the other to green. • Since each color is recorded by the eye as the levels of excitation of the cone caused by the incoming photons, the eye can perceive colors that aren’t in the spectrum (magenta, turquoises, …) Chapter 4 -- Color

  5. Computer Color • On a color computer screen, the hardware causes each pixel on the screen to emit different amounts of red, green, and blue light. (RGB values) • They are often packed together, sometimes with a fourth value, called blending, or A) • See Chapter 6 for a discussion on alpha values. Chapter 4 -- Color

  6. The color information for each pixel can be stored in one of two major ways: • RGBA mode (each of the four values are stored at each pixel) or in • color-index mode (a single number is stored at each pixel and it is an index into a table called a color map) • Since color maps are controlled by the window system, there are no OpenGL commands to do this. • All examples in this book use GLUT routines to initialize this (see Appendix D for more info) Chapter 4 -- Color

  7. Sample Code: • glColor3f(1.0, 0.0, 0.0); • glBegin(GL_POINTS); • glVertex3fv(points_array); • glEnd( ); • The R, G, and B values can range from 0.0 (none) to 1.0 (full intensity) • for example (0.0, 0.0, 1.0) represents the brightest possible blue. Chapter 4 -- Color

  8. RGBA versus Color-Index Mode • In either color-index or RGBA mode, a certain amount of color data is stored at each pixel • This amount is determined by the number of bitplanes • If there are 8 color bitplanes, there are 8 color bits per pixel, and hence 28 = 256 different values or colors that can be stored at that pixel. Chapter 4 -- Color

  9. RGBA Display Mode • In RGBA mode, the hardware sets aside a certain number of bitplanes for each of the R, G, B, and A components (it usually is, but is not necessarily the same number per part) • values are typically stored as integers -- not floats • and the float values are scaled to the number of available bits for storage and retrieval • glGetInetegerv( ) with GL_RED_BITS, … will let you find out how many bits are available. Chapter 4 -- Color

  10. Color-Index Display Mode • With color-index mode, OpenGL uses a color map (or lookup table), • which is similar to using a palette to mix paints to prepare for a paint-by-umber scene • A computer stores the color index in the bitplanes for each pixel. Then those bitplane values reference the color map, and the screen is painted with the corresponding red, green, and blue values from the color map. • The number of colors is limited by the size of the color map (which is limited by the number of bit planes) Chapter 4 -- Color

  11. Choosing between RGBA and Color-Index Mode • You should base your decision to use RGBA or color-index mode on what hardware is available and on what your application requires. • In general, use RGBA mode whenever possible. It works with texture mapping, and works better with lighting, shading, fog, antialiasing, and blending. Chapter 4 -- Color

  12. Specifying a Color and a Shading Model • Specifying a Color in RGBA Mode • In RGBA mode, use the glColor*( ) command to select the current color • There are two major variants (3 or 4 parameters) • Each can have 8 different data types • and each can take them directly or in a vector. Chapter 4 -- Color

  13. Specifying a Color in Color-Index Mode • In color-index mode, use the glIndex*( ) command to select a single color index as the current color index. • glIndex( ) also has a bunch of options in data types. • glClearColor( ) and glClearIndex( ) set the clearing colors. • OpenGL does not have any routines to load values into the color-lookup table. • Window systems typically already have such operations. • GLUT has the routine glutSetColor( ) to call the window specific commands Chapter 4 -- Color

  14. Specifying a Shading Model • A line or filled polygon primitive can be drawn with a single color (flat shading) or with many different colors (smooth shading or Gouraund shading). • void glShadeModel(Glenum mode); • Sets the default shading model. • the parameter can be either GL_SMOOTH (the default) or GL_FLAT. Chapter 4 -- Color

More Related