
(0,0,0) ← The origin, the center of our defined space.
(2,0,4) ← 2 units to the right, 4 units towards us, on the center of the y-axis.
(3,-4,-2) ← 3 units to the right, 4 units down, and 2 units away from us.
Got the hang of it? Then lets plot some points with OpenGL. We can use the function glVertex to specifiy vertices, flanked by calls to glBegin and glEnd:
glBegin(GL_POINTS); /* We want to draw points */
glVertex3f(2.0, 0.0, 4.0); /* Specify a couple of vertices */
glVertex3f(3.0, –4.0, –2.0);
glEnd(); /* End points */
As you can see, glBegin tells OpenGL we want to start drawing (as well as WHAT we want to start drawing), and glEnd tells it to stop. The great thing about OGL's method of 3D drawing is it's flexibility – lets say we want to draw some lines:
glBegin(GL_LINES); /* lets do some lines now */
glVertex3f(6.0, 4.0, 2.0); /* here's one */
glVertex3f(2.0, –4.0, 3.3);
glVertex3f(5.0, 8.0, 8.0); /* here's another */
glVertex3f(-4.7, 5.0, –3.0);
glVertex3f(0.0, 0.0, 0.0); /* and another! */
glVertex3f(6.0, –1.0, –7.0);
glEnd();
Note that we now have one line for every two vertices. If you specify an odd number, the last vertex is ignored.
Now lets do some shapes. OpenGL specifies 6 different polygon primitives: GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS, GL_QUAD_STRIP, and GL_POLYGON. Triangle and quad strips are shortcuts for building polygons next to each other, and likewise a triangle fan is a group of triangles that share a center point. GL_POLYGON can specify a general polygon with any number of vertices. The one you should use most often is GL_TRIANGLES, since most graphic accelerators are optimized for triangle operations. Here's an example of a generic triangle:
