13.016 Introduction to Geometric Modeling and Computation
OpenGL 3D Geometry
Geometry is drawn by specifying the geometric type and a sequence of vertices. In other words specifying a sequence of glVertex calls between a glBegin/ glEnd pair.
Several forms of the vertex function are available for different dimensionality and argument types:
glVertex{234}{sifd}(x, y [, z [, w]]);
where the curly braces { and } indicate the selection of one character from the list of alternatives, and the square brackets [ and ] indicate optional arguments.
Internal to OpenGL, all coordinates are stored and manipulated as 4 dimensional floating point values, (x, y, z, w). These 4 dimensional coordinates are called homogeneous coordinates.
We can freely convert between 4D homogeneous, (x,
y, z, w), and 3D cartesian
coordinates,
(x', y', z'), as follows:
(x', y', z') = (x/w,
y/w, z/w)
(x, y, z, w) = (x'w,
y'w, z'w, w)
Note that setting w = 1 converts a 3D coordinate to a homogenous coordinate without changing the values of any of the individual scalar components.
Since glVertex4f is the canonical vertex function, the other variant formats merely pass the appropriate arguments:
glVertex2f(x, y) { glVertex4f(x, y, 0.0, 1.0); }
glVetex3f(x, y, z) { glVertex4f(x, y, z, 1.0); }