OpenGL Course - Session 2
  • Last session:
    • OpenGL state machine 
    • Basic drawing commands
  • Topics for this session:
    • Fundamental drawing commands
    • Drawing complex geometric objects
  • Goal:  Apply these techniques in this week's lab

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

A "Drawing Survival Kit"

  • Almost all OGL applications require some common basic commands
    • Clearing the screen
    • Specifying color
    • Drawing primitives

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

Clearing the bitplanes:

glClearColor(0.0, 0.0, 0.0, 0.0);
glClearDepth(1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  • Other bitplanes ara available to address with glClear() 
Table 2-1

Question:  Why is the clear command glClearColor() instead of glClearColor4f()?
 

  • glClear() is generally an optimized routine - use it!  (avoid the "roll your own" mentality

  •  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     

  • Specifying color
    •  The current color is a state variable 
      • All objects are drawn with that color until the color is re-specified
    •  Color is specified with glColor3f() and glColor4f()

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     

    Forcing Completion of Drawing
    • glFlush() signals the state machine to begin processing the previously-executed commands.
    • glFinish() blocks until the state machine completes execution
    • More on these topics later ...

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     

    Coordinate Systems
    • Figure 2-1

    •  
    • Whenever a window is resized the application must:
      • Re-establish the rectangular region that will be the new rendering canvas
      • Define the coordinate system to draw the objects (Example 2-1)

       
       
       
       
       
       
       
       
       
       

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     

    Describing Points, Lines, and Polygons
    • OpenGL constructs are slightly different than "pure" mathematical constructs
      • OpenGL is implemented with a finite state-machine - there are machine limits to fp precision (roundoff, finite resolution ...)
      • 2-D constructs are processed as 3-D (z = 0)
      • Internal OGL processing is done in homeogeneous coordinates <x y z w>
      • Lines in OGL are really line-segments - fixed endpoints
       

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     

    Describing Points, Lines, and Polygons (cont)
    • Polygons represent enclosed areas specified by 3 or more vertex locations
    • They may be filled or unfilled

    •  

       
       
       
       
       


       

    • Some restrictions are made to specify what is a "valid" polygon:
      • Must be "flat"
      • Must be convex
    • No limit on the number of verticies in a polygon (but ...)

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     

    Drawing Rectangles
      void glRect{sifd}(TYPEx1, TYPEy1, TYPEx2, TYPEy2); void glRect{sifd}v(TYPE*v1, TYPE*v2); 

      Draws the rectangle defined by the corner points (x1, y1) and (x2, y2). 

       

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     

    Curves and curved surfaces
    • Figure 2-5