Pixels, Bitmaps, Fonts, and Images
  • Objectives:
    • Position and draw bitmapped data
    • Read pixel data between the framebuffer and memory
    • Copy pixel data from one color buffer to another or to another location in the framebuffer
    • Control pixel data formatting 
    • Pixel data transformations



    Image from http://www.dtc.army.mil/hpcw/1999/tucker/index.html



     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Polygons, Bitmaps, and Image Data
  • So far most of our discussion has concerned geometric objects
  • Other data may be managed by OpenGL
    • Bitmaps (usually used for font characters)
    • Image data
  • Bitmaps and image data are arranged in retangular arrays of pixels
    • Bitmaps are 1-bit deep
    • Image data are generally multi-component
    • Bitmaps generally function as color masks (or blend masks)

     
     
     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Bitmaps and Fonts
  • A bitmap is a rectangular array of 0's and 1's 
    • Serves as a drawing mask 
    • Applied to a rectangular portion of a window
    • 0's in the bitmap do not affect the framebuffer
  •  glRasterPos() and glBitmap()  are used to position and draw bitmaps on the screen.
  • GLubyte rasters[24] = {
       0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
       0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
       0xff, 0xc0, 0xff, 0xc0};
    
    void init(void)
    {
       glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
       glClearColor (0.0, 0.0, 0.0, 0.0);
    }
    
    void display(void)
    {
       glClear(GL_COLOR_BUFFER_BIT);
       glColor3f (1.0, 1.0, 1.0);
       glRasterPos2i (20, 20);
       glBitmap (10, 12, 0.0, 0.0, 11.0, 0.0, rasters);
       glBitmap (10, 12, 0.0, 0.0, 11.0, 0.0, rasters);
       glBitmap (10, 12, 0.0, 0.0, 11.0, 0.0, rasters);
       glFlush();
    }
    
    
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Current Raster Postition
  • The current raster position is the origin where the next bitmap or image is to be drawn
    • Defines the lower-left pixel
  •  To render in screen coordinates the modelview and projection matrices should be defined as such:

  •  

     
     
     

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, (GLfloat) width, 0.0, (GLfloat)
      height);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
     

  •  Current raster position can be queried with glGetFloatv(GL_CURRENT_RASTER_POSITION)

  •  

     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Drawing the Bitmap
  • glBitmap(GLsizei width, GLsizei height, GLfloat xbo, GLfloat ybo, GLfloat xbi, GLfloat ybi, GLubyte *bitmap);


  •  
  • The current raster position is incremented by xi and yi
  • Floating point values are rounded to integer pixel values
  • NOTE!  Fonts cannot be rotated - aligned to framebuffer

  •  

     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Defining the Color of the Bitmap
  • Color is bound before raster position is defined

  • glColor3f(1.0, 1.0, 1.0);
    glRasterPos3fv(position);
    glColor3f(1.0, 0.0, 0.0);
    glBitmap(...)

    The font color is WHITE (!)
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  End of Presentation
  • Fonts can be used in display list definitions


  •  

  •  Refer to font.c in examples

  •  

     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Images
  • Fin 8

  •  

     

  •  

  •  

     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  End of Presentation
  • Fin 9

  •  

     

  •  

  •  

     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  End of Presentation
  • Fin 10

  •  

     

  •  

  •