Back to Title Page

Next Entry→

July 2, 2005

 

Well I already wrote something about how nice it was to sleep in, but since that document just mysteriously disappeared, I don’t feel so nice anymore.  I remember griping before, ever so passively, about cleaning up first thing am after cooking last thing pm: the worst pesto pizza ever.  So I’m a grouch.  You got a problem with that?

 

I’ve been investigating parsers, and that led me to something called The Code Project, http://www.codeproject.com/ where there is a fairly well-developed parser available http://www.codeproject.com/cpp/MathieuMathParser.asp as well as other good stuff, such as http://www.codeproject.com/opengl/wrl_viewer.asp

 

OpenGL is an application programmer’s interface (API) that provides ready-made graphics functions for rendering views of various colored and textured geometric objects under various lighting conditions.  The geometric properties of an object can be manifest in many different ways.  For instance, a line may appear fat, solid blue and shiny in a bright light or thin, dotted green and matt in a pale light.  An image also requires an observer (it’s not a picture if no one looks at it.)  In OpenGL, this is called the virtual camera.

 

From another perspective, OpenGL is a state machine with I/O.  The input is function calls from an application program and the output is a sequence of pixel renderings on a computer screen.  OpenGL takes descriptions of geometric objects and creates a pixel array from these.  From this perspective you can think of the inputs as the geometric objects and attributes of these objects (color, texture, position, lighting, etc) as the state of the machine.  The way the objects are processed to produce output depends on the state of the machine.

 

OpenGL employs a pipeline model. Primitive geometric objects generally consist of a set of vertices which then enter a 4-stage pipeline:

  1. Transformer: rotate, translate and scale type stuff. 
  2. Clipper:  Is all or part of it in view?
  3. Projector: Position relative to camera. 
  4. If visible, convert to colored pixel elements.

The high throughput value of the pipeline model compromises the ability to incorportate global effects such as overlaps/shadows of other geometric objects.

 

We can group the 200+ functions of OpenGL by functionality:

 

  • Primitive functions define the elements that can produce images on the screen, either geometric primitives like polygons in 2,3 or 4D or image primitives such as bitmaps.
  • Attribute functions determine color, texture, brightness and other properties of primitives.
  • Viewing functions determine the position, direction and lens type of the virtual camera.
  • Windowing functions are not central to openGL but are important and contained in separate libraries such as GLUT.  They control the windows on the screen and mouse/keyboard interactions.
  • Control functions toggle various OpenGL features and to query the capabilities of an implementation.

 

The OpenGL functions are contained in libraries usually named GL and GLU.  GL contains all the essential functions and the utility library, GLU, builds on these to create further useful functions.  You can tell what library a function is from by its name. For instance, glVertex3f() is from GL and gluOrtho2D() is from GLU.

 

Many OpenGL functions have multiple forms to accommodate different types.  For example   glVertex3f() and  glVertex3i().  Sometimes the notation glVertex*()  is used to refer to all forms of the function.

 

The header files GL.h and GLU.h contain specific parameter values for many functions. Prefixes GL_ and GLU_ indicate which header the macro comes from; GL_LINES and GL_LIGHTO, for instance.  Header GL.h  also contains lines such as
         typedef GLfloat float

 and then typically GLfloat is used instead of float.  There are some other more unusual types such as GLclampf for floats between 0.0 and 1.0.  It’s the local vernacular.

 

Many functions also include alternatives that allow parameters through pointers to arrays.  These function have a “v” before th argument list.  For examples, the function glVertex3fv() may used as follows:

   GLfloat point[3] = {1.0, -2.5, 0.5};

   glVertex3fv(point);

 

Compiling an OpenGL program in different environments may require parameters such as in UNIX: 
   cc myapp.c -0 myapp –lglut – lGLU –lGL –lXll  -lm

Or Linux:
   -L/usr/X11R6/lib

You can make a simple makefile that works UNIX and Linux.  I’ll be working mostly with Windows based console applications with Visual C++ with the OpenGL32.dll and glu32.dll files in the system folders and the corresponding lib files in ..\VC\lib and the includes in ..\VC\include\GL. 

 

A good starting place for web-based resources is www.opengl.org and www.cs.unm.edu/~angel and the redbook and bluebook,