Visualization, Spring'98, Yap

LECTURE 3: THE OPENGL MODEL

  1. INTRODUCTION

    There is a very simple model for raster graphics: it basically provides the means to the color of each pixel. E.g., write(color,x,y) would specify the color of pixel (x,y). This single operation would in principle be sufficient, but there are simple ways to enhance this model.

    The OpenGL model is a pipeline model that is inherently 3D, but easily accomodates 2D applications.

  2. NUMBER TYPES

    These include GLfloat, GLint, GLdouble, GLuint, etc, corresponding to the usual number datatypes in the C language. There is also GLvoid.
    -- More on Number Types.
  3. NAMING CONVENTIONS

    OpenGL command or functions have names with 3 parts. E.g.
    glVertex3f
    The 3 parts are:
    • The prefix gl that is common to all OpenGL functions,
    • Some descriptive name (Vertex)
    • A type suffix. Here, 3f tells us that the vertex is specified by 3 floats.

    -- More Naming Conventions
  4. VERTICES

    The most fundamental object in OpenGL is the vertex. There are are 2-D and 3-D versions of vertices and these are specified by 2 or 3 real numbers respectively:
    void glVertex2f(GLfloat x, GLfloat y);
    void glVertex3f(GLfloat x, GLfloat y, GLfloat z);
    void glVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w);
    void glVertex3i(GLint x, GLint y, GLint z);
    void glVertex3fv(GLfloat v[3]);
    Note the use of vectors in the last variant of Vertex.
  5. PRIMITIVES

    The basic geometric objects of OpenGL are called primitives. These primitives are basically points, line segments and polygons, and are defined by specifying a sequence of vertices between the glBegin/glEnd pairs:
    void glBegin(GLenum mode);
    ...list of vertices...
    glEnd(void);
    E.g.,
    void glBegin(GL_LINES);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(1.0, 1.0, 1.0);
    glEnd(void);
    There are 10 primitives, and these are specified by the mode in the glBegin command.

    CUBE EXAMPLE

  6. FRAGMENTS versus PIXELS

    The primitives are ultimately rendered on the screen. A primitive will affect many pixels. But conversely, a pixel may be affected by many primitives.
    -- OpenGL introduces abstract entities called fragments.
    -- The process of rasterization generates a set of fragments from each primitive.
    -- Each fragment has several attributes: the two most important are its color (RGB values) and an associate pixel. But a fragment may also have a depth value and a texture value.
    -- MORE ON FRAGMENTS
  7. VERTICES versus POINTS

    Note that vertices are distinguished from points: the latter is one of the geometric primitives of OpenGL. Vertices are even more basic than points -- being the building blocks of primitives.
  8. VERTEX ATTRIBUTES

    Vertex Normals Vertices have normals, i.e., a direction vector.
    How to assign normals
    Use of vertex normals: specifying lighting and color of generated fragments.
  9. SYNTHETIC CAMERA SYSTEM

    Two sets of parameters:
    CAMERA COORDINATE SYSTEM:
    gluLookAt( eyePosition, LookAtPoint, UpVector)
    [p.183, Angel]
    -- this should be used to transform the MODEL VIEW MATRIX .
    PROJECTION OR IMAGING PARAMETERS
    (1) gluFrustum (xmin, xmax, ymin, ymax, zmin, zmax)
    (2) gluPerspective( fov, aspect, near, far)
    (3) gluOrtho(left, right, bot, top, znear, zfar)
    (4) gluOrtho2D(xmin, xmax, ymin, ymax, zmin, zmax)
    -- NOTE that the parameters are in camera coordinates.
    -- glFrustum assumes the perspective projection
    -- glPerspective can be seen as a "symmetric" special case of glFrustum.
    -- ALL THESE TRANSFORMATIONS SHOULD BE APPLIED TO THE PERSPECTIVE MATRIX
  10. COORDINATE SYSTEMS

    Local or Object Coordinates
    -- also called model coordinates
    Global or World Coordinates
    -- local coordinates are "absorbed" into this global coords.
    Eye or Camera Coordinates
    -- in openGL, this is combined with the global coords in the MODEL VIEW matrix.
    Clip Coordinates
    -- This is the coordinates after PROJECTION is done
    -- Normalized Device Coordinates (NDC): this is clip coordinates after dividing by the w-coordinate.
    -- The view frustum becomes a standard cube in NDC. The coordinates here are device and model independent!
    Window Coordinates (2 dimensional)
    -- View Port Coordinates
  11. TRANSFORMATIONS

    There are three 4x4 transformation matrices:
    model view, projection and texture matrices.
    These are used to transform vertices and their normals before they are used in rasterization.
    At any moment, one of these three matrices is current. You make a matrix current by invoking
    glMatrixMode( MODE )
    where MODE is GL_MODELVIEW, GL_PROJECTION or GL_TEXTURE.
    The commands glMultMatrix, glRotate, glTranslate, and glScale are used to manipulate the current matrix (by post-multiplication).
    -- Example
    OpenGL combines the Eye Coordinates with Global Coordinates into the MODEL VIEW matrix. This can cause some confusion
    Transforming to Clip Coordinates
    -- Clipping is done in two places (this is the second)
    -- The other clipping is done in eye coordinates using glClipPlanes, and is application specific.
    Transforming to Window Coordinates

[PREVIOUS LECTURE] [NEXT LECTURE] [ALL LECTURES] [CLASS PAGE]