CS-460/560, Week 3-AB
Spring 1998
R. Eckert


1. Lowest Level (earliest)-- Assembly/machine language;
     Programs drive hardware directly
     Fast, but non-portable
     Difficult to program
     Prone to errors

2. Medium Level (General Programming Packages)--
   A. Extensions to high level languages-- graphics libraries
      e.g., Borland's BGI, Windows' GDI, Silicon Graphics GL,
            Microsoft's DirectX
      More portable, but still platform dependencies
      Easier to program
      Usually slower, but with optimized compilers, not so bad

   B. Standard Graphics Packages-- Set of specifications
      Supposedly language/platform independent
         Usually with bindings for many high level languages
           -->Syntax for accessing graphics functions
         Examples: GKS, PHIGS, OpenGL

3. Special-purpose Application packages--
      e.g., Corel Draw, 3D Studio, Harvard Graphics
      Good for what they do, but very specific uses

We'll be working at level 2 for most of this course.

Describing the positions of objects in scenes--Need coordinate systems
   2-D and 3-D Cartesian systems used universally
   2-D: Position given by two numbers (x,y) 
        Measure distance along two mutually perpendicular axes
   3-D: Position given by three numbers (x,y,z) 
        Measure distance along three mutually perpendicular axes
   Other systems commonly used, depending on symmetry--
        Spherical (rho, theta, phi)
        Cylindrical (r, theta, z)
        Conversion formulas used

Types of coordinate systems--

1. Modeling coordinates system (MC): System used by the programmer
   (modeler) to describe a single object. Can be 2-D or 3-D, depending
   on object being modeled. Origin picked so object description is as
   easy as possible. Scale and units also determined by the object.
   Varies from object to object.

2. World Coordinate System (WC): Reference system used to position
   objects in a scene. Can be 2-D or 3-D, depending on the scene.
   Origin, scale, units are scene specific. Coordinate transformations
   are used to go from a modeling system to the world coordinate system
   for a scene. Effectively places an object in the scene. This is
   called a modeling transformation.

3. Device Coordinate System (DC): Coordinates used by the output device.
   Units are usually pixels. Always 2-D. Varies from one hardware
   platform to another. Graphics software must map (transform) from
   world coordinates to device coordinates. This transformation called
   the Viewing Transformation. If the world coordinate system is in 3-D,
   a projection transformation is also involved.

Normalized Device Coordinates (NDC): 2-D system such that x: 0-->1;
   y: 0-->1; Intermediate between WC and DC; hardware-independent.

Graphics Transformation Pipeline:

   MC --------------> WC -------------> NDC ------------------> DC
      Modeling Xform     Viewing Xform      HW-dependent Xform

The first two transformations are device independent.

Window-- A rectangular (2-D) or Rectangular parallelepiped (3-D) expressed
in world coordinates (e.g., xwmin, ywmin, zwmin, xwmax, ywmax, zwmax).
Specifies a part of the scene of interest.

Viewport-- A rectangular portion of the screen to which a window is
mapped. Expressed in device coordinates (e.g., xvmin, yvmin, xvmax,

The mapping from a window to a viewport is called a window to viewport

Clipping-- Removal of parts of the scene outside of a window or
viewport. The graphics system may perform clipping with respect to a
window or a viewport.

Animation techniques using windows/viewports/clipping--

   Zooming-- Change window size from frame to frame, clip, and
             transform==>scene appears to approach or recede from

   Panning-- Translate the window from frame to frame, clip, and
             transform==>scene appears to move across the screen.


1. Output Primitives--Building blocks for drawing pictures.

(The following gives example function calls from Windows, OpenGL, and
other systems.)

 Most primitive (pixels)--
    SetPixel(hDC,x,y,colref);  // Windows, set pixel at (x,y) to a color
    putpixel (int x, int y, int color); // Borland
    glBegin (GL_POINTS);  // OpenGL -- one way
      glVertex2f (x, y);  // 2==>2D, f==>floating pt
    glEnd();              // current drawing color used

    colref = GetPixel(hDC,x,y); // Windows function to return pixel color

 Lines --
    MoveToEx(hDC,x,y,NULL);  // Windows call to set current position
    LineTo(hDC,x,y);  // Windows, from current position to (x,y); current pen
    line (x1,y1,x2,y2);  // Borland line drawer, current color
    glBegin (GL_LINES);  // OpenGL, endpoint vertices before glEnd()
                         // --> polyline if # of vertices > 2
 Polygons --
    Polyline(hDC,lppts,num_pts); // Windows; address of array of points,
                                 // # of pts; current pen used
    Polygon(hDC,lppts,num_pts); // Windows; address of array of points,
                                // # of pts; current pen used,
                                // closed--current brush fills it
    drawpoly(num_pts, address of list of x,y coordinates);
             // Borland--Makes a polyline if last vertex != first vertex
    fillpoly (num_pts, addrPts) //Borland, uses current fill color/pattern
    glBegin (GL_POLYGON); // OpenGL, polygon vertices before glEnd()

 Lots of others--
    Windows--See prior notes on Windows programming
    Borland: arc(), circle(), ellipse(), rectangle(), ...

    Windows-- TextOut(hDC,x,y,lpszString,cStringLength);
    Borland-- outtext (string ptr);  // appears at current position
              outtextxy (x,y,string ptr);  // appears at (x,y), current font
    OpenGL-- Use display lists or GLUT library ftns.

 Some graphics software systems include 3-D primitives
    [e.g., OpenGL's auxiliary library: sphere, cube, cone, ...]

2. Attributes (State Variables)--
         Properties of primitives (how they appear; e.g., color,
         line style, text style, area fill patterns, etc.)
         Usually modal ==> values retained until changed
    Windows--See prior notes on Windows programming
         FloodFill(hDC,x,y,bordercolor); // current brush used
    Borland--use set**() to set an attribute, get**() to get current value
         setcolor (color);  // foreground (drawing) color
         setbkcolor (color);  // background color
         setlinestyle (style, pattern, thickness);  // for lines
         setfillstyle (pattern, color);  // for filled primitives
         floodfill (x,y,bordercolor); // any closed area
         settextstyle (font, direction, charsize);  // text style
    OpenGL-- glProperty(); where "Property" is state variable to set
              e.g., glColor3f (R,G,B);
              Lots of others.

3. Transformations-- Done with matrix math
         Setting windows/viewports, Window-to-Viewport transformation
         Moving objects--Geometric Transformations 
           (e.g., translation, rotation, scaling)
         Mapping from one coordinate system to another (Modeling/Viewing)
         Change of viewpoint
         Different types of projections
     Windows handles this with Mapping Modes (see online documentation)
     Borland has essentially nothing [setviewport(L,T,R,B,clipflag)]
         ==> programmer must implement his/her own package.
     OpenGL is very rich [glLoadMatrix(), glRotatef(), glTranslatef(),
            glScalef(), glViewport(), glFrustum(), glOrtho(), etc.]

4. Segmentation--Dividing a scene into component parts for manipulation.
     Windows and Borland have nothing (strictly immediate mode).
     DirectX (Direct3D) has support for retained mode.
     OpenGL--Display lists--Groups of OpenGL commands that have been stored
                            for later execution. Can be hierarchical.
     PHIGS uses hierarchical segments.

5. Input/Interaction--Obtain data from input devices or graphics system
          ==> user can manipulate the scene interactively.
       Windows--Built into event-driven, message-based paradigm.
       Borland provides only basic C Input, and "Query" (get) ftns.
          To use mouse, must rely on int 33h mouse driver services.
       OpenGL--Auxiliary libraries (aux, GLX, GLUT) provide these features.
          Uses event-driven paradigm with input-handling callback ftns.
          e.g., auxMouseFunc() glutMouseFunc()--these and others take as a
          parameter a pointer to an appropriate callback function that the
          programmer writes to handle the input.

6. Control/Housekeeping--init graphics system, put window up, etc.
    Windows--Extensive support; RegisterClass(), CreateWindow(), etc.
    Borland-- initgraph(), closegraph(), cleardevice(), clearscreen();
    OpenGL-- Use of auxiliary libraries-- [e.g., auxInitWindow(),
     auxInitDisplayMode(), auxMainLoop(ptr to function that draws the scene)]

7. Storing/Retrieving manipulating bitmapped Images--
   (e.g., BitBlT--Bit Block Transfer)
    Windows-- Device Dependent Bitmaps (BitBlt(), StretchBlt(), etc.
              But very slow
              Device Independent Bitmaps--faster
              DirectX (DirectDraw)--flipping surfaces--very fast!
    Borland-- getimage (L,T,R,B, array address);
              putimage (L,T, array address, Raster-op);
    OpenGL--  glReadPixels(); glDrawPixels(); glCopyPixels();

8. Photorealism-- Hidden surfaces, lighting, shading, reflection props...
    Windows-- Very little support
       DirectX (Direct3D)--Quite a bit of support
    Borland-- nothing
    OpenGL-- A lot! [e.g., light sources, lighting models, material
      properties, blending, antialiasing, fog, depth buffer, etc.]