CS 381 Fall 2012  >  Lecture Notes for Tuesday, September 4, 2012

CS 381 Fall 2012
Lecture Notes for Tuesday, September 4, 2012

Introduction to OpenGL

What is OpenGL?

Professional-quality 2-D/3-D graphics API. Note: API = Application Programming Interface. (Can be implemented, but is not an implementation itself.)

OpenGL does:

OpenGL is not aimed primarily at:

OpenGL does not:

The job of OpenGL is to create an image in a framebuffer.

Parts of OpenGL

Core OpenGL

The OpenGL Utilities (GLU)

OpenGL Extensions

The Design of OpenGL

We deal with OpenGL via function calls, which implement OpenGL commands.

OpenGL functions as a state machine. There are three kinds of functions:

Drawing is done via primitives. A state might be used to set an attribute of a vertex in a geometry primitive (e.g., its color) or a uniform property of a primitive as a whole (e.g., the width of a line).

Thus, you can think of OpenGL in an object-oriented sense. Commands are like member functions. States are like data members. The first 2 kinds of functions above are like setters and getters. The thing that corresponds with the object itself is an OpenGL rendering context. Typically, there is one context for each window.

Naming conventions for core OpenGL.

GLU uses similar conventions, with “glu” instead of “gl”.

OpenGL defines its own types, which have at least a specified minimum precision on all systems. Some of these:

So, for example, GLdouble is probably the same as double, but might not be. Be careful when dealing with pointers & arrays.

The C language cannot overload functions the way C++ can. Thus, some OpenGL commands have several forms allowing for different parameter types.

GLUT Programs

What is GLUT?

GLUT = The OpenGL Utility Toolkit.

Some Details

The GLUT header is <GL/glut.h>. This includes the OpenGL and GLU headers for you.

Including the GLUT header in a system-indpendent way is a bit tricky. First, Apple puts it in a nonstandard place. Second, some implementations have a problem involving the exit system call, and so <cstdlib> should be included before the GLUT header. Putting it all together, the following seems to work everywhere.

#include <cstdlib>       // Do this before GL/GLUT includes
using std::exit;
#ifndef __APPLE__
# include <GL/glut.h>    // GLUT stuff, includes OpenGL headers as well
#else
# include <GLUT/glut.h>  // Apple puts glut.h in a different place
#endif

GLUT naming conventions are like those for GL, using “glut” instead of “gl”.

Program Structure

We looked at sample1.cpp here.

The structure of our programs is dictated by GLUT.

Rules for callbacks in this class.


CS 381 Fall 2012: Lecture Notes for Tuesday, September 4, 2012 / Updated: 4 Sep 2012 / Glenn G. Chappell / ggchappell@alaska.edu