Color
  • The main purpose of an OpenGL application is to determine the color of each pixel in the window

  •  
  • Contents of this session:
    • Color Perception
    • Computer Color
    • RGBA vs Color-index
    • Specifying a Color and Shading Model

     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Color Perception
  • The Human Visual System (HVS) recognizes light in the range from 390 nm (violet) 720 nm (red) 
  •  Perceived colors are a combination of light of different frequencies
  • The cone cells in the retena are sensitive to red, green and blue frequencies
    • (the HVS is least sensitive to blue)
  •  A monitor emultates visible colors by lighting pixels with a combination of red/green/blue colors.
  • OpenGL represents color in RGB - other color models (HLS/HSV/CMYK) must be converted to and from RGB.

  •  

     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Computer Color
  • The hardware causes different amounts of R/G/B light emmision for each pixel
  •  Two ways to encode the color information for the application
    • RGB (or RGBA)
    • Color index
  •  Color index mode stores table entries for each pixel
  • The colormap is not fixed size and can vary between platforms

  •  

     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Colorspace

     (image from http://www.swin.edu.au/astronomy/pbourke/colour/colourspace/)
     
  • Red, Green, and Blue intensities vary from 0.0 to 1.0 
  •  Each axis of the color space represents RGB intensities
  • Examples of OpenGL colors:
    • Red:          glColor3f(1.0, 0.0, 0.0)
      Yellow:     glColor3f(1.0, 1.0, 0.0)
      Magenta:  glColor(1.0, 0.0, 1.0)
  • NOTE! other operations (texture/lighting/blending) may affect the final color in the framebuffer

  •  

     
     
     
     
     
     
     

 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Coloring
  • Early in execution, the color display mode (RGBA or Color Index) is set
  •  The mode cannot be changed after it is set
    • But there are workarounds ...
  • Color is based on several factors:
    • The per-vertex color definition (via glColor3f())
    • The interaction of the light source(s) with the surface normal and the material properties
    • Rasterization
    • The shading model
    • Blending 
    • Texturing
    • Anti-alising
    • Fog
    • Bit-wise operation (logical ops)

     
     
     
     
     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  RGBA vs Color Index Mode
  • In either mode an amount of color data is stored for each pixel
  •  A bitplane stores a single bit of color information for each pixel
  • 8 bitplanes can store 28 colors
  • Bitplanes are generally evenly devided for R/G/B (but not always)
    •  
      Use glGetIntegerv( GL_RED_BITS | GL_GREEN_BITS | GL_BLUE_BITS | GL_ALPHA_BITS | GL_INDEX_BITS)
  •  A common RGB mode uses 8/8/8/8 for the framebuffer
    • 224 colors (but only 256 shades of grey!)

     
     
     
     
     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

 
 
  Intensity and Perception
  • The HVS is not linear in perception of light intensity (a good thing!)
  •  Closer to eponential (gamma correction)

  •  

     


     (Chart from http://www.exluna.com/bmrt/images/gamma.gif)
     

  •  Modify the system's gamma with xgamma or gamma

  •  

     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  RGB Display Mode
  • The hardware reserves a certain number of bitplanes for of the RGBA components 
  • The components are generally stored as integers
  • Regardless of the number of bitplanes the components range between 0.0 and 1.0

  •  

     


     
     

  •  NOTE!  The Alpha value has no direct effect on the rendered pixel

  •  

     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Dithering
  • Some graphics hardware will use dithering to increase the aparrent number of colors
  •  Dithering may be advantageous in some instances
    • To provide double buffering
    • To get a particular visual from the system


     
     

  •  Dithering is enabled by default - use glDisable(GL_DITHER) to disable

  •  

     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Color Index Display Mode
  • In color index mode a colormap (pallette) is used to specify color
  •  The bitplanes store the index of the colormap


  •