| CS 381 Fall 2012 > Lecture Notes for Tuesday, September 4, 2012 |
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.
Core OpenGL
<GL/gl.h>.The OpenGL Utilities (GLU)
<GL/glu.h>.OpenGL Extensions
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.
gl”.
Words capitalized & run together.glClearColor”.glVertex2d”,
the “2d” indicates 2 parameters
of type GLdouble.GL”.
All upper-case, “_” between words.GL_TRIANGLE_STRIP”.GL”.
Next word not capitalized;
others capitalized and run together.GLdouble”.GLU uses similar conventions, with “glu” instead of “gl”.
gluScaleImage.GLU_TESS_ERROR.GLUtesselatorObj.OpenGL defines its own types, which have at least a specified minimum precision on all systems. Some of these:
GLint. Signed integer, 32 bits.GLubyte. Unsigned integer, 8 bits.GLfloat. Floating-point, 32 bits.GLdouble. Floating-point, 64 bits.GLenum. The type of OpenGL-defined constants like
GL_TRIANGLE_STRIP.
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.
glVertex* command can take 2, 3, or 4
values of various types.
glVertex2d
takes 2 parameters of type GLdouble.glVertex3f
takes 3 parameters of type GLfloat.glVertex3dv
(“v” for “vector”)
takes a single parameter of type (GLdouble *),
which should be a pointer to an array of 3 GLdouble values.glTranslate* command always takes 3 parameters.
glTranslatef
takes 3 parameters of type GLfloat.glTranslated
takes 3 parameters of type GLdouble.GLUT = The OpenGL Utility Toolkit.
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”.
glutInitDisplayMode.GLUT_MIDDLE_BUTTON.
We looked at
sample1.cpp
here.
The structure of our programs is dictated by GLUT.
Rules for callbacks in this class.
ggchappell@alaska.edu