CSc 433/533: OpenGL and GLUT Tutorial

  1. OpenGL Primitives
  2. OpenGL provides the following primitives for use in constructing geometric objects.



    Each geometric object is described by a set of vertices and the type of the primitive to be drawn. Whether and how the vertices are connected is determined by the primitive type. For a more detailed discussion of these primitives, refer to Section 2.6.1 Begin and End Objects of the OpenGL Specification.

    With OpenGL, all geometric objects are ultimately described as an ordered set of vertices. The command glVertex*() is used to specify a vertex. In this class, we will only use the two-dimensional capabilities of OpenGL, so vertices will be specified using, for example, glVertex2i(). All calls to glVertex*() should occur between a glBegin() and glEnd() pair. Drawing occurs each time a glBegin() and glEnd() pair is reached with the exception of display lists which we won't cover but which are explained in Section 5.4 of the OpenGL Specification.

    It is important to note that OpenGL commands are not necessarily executed as soon as they are issued. It is necessary to call the command glFlush() to ensure that all previously issued commands are executed. glFlush() is generally called at the end of a sequence of drawing commands to ensure all objects in the scene are drawn. Some GLUT commands, such as glutSwapBuffers(), implicitly call glFlush().

    The following example illustrates the different results of each of the primitive types applied to the same set of vertices.

    primitive.c output

    Doesn't it look like the words slant down to the right?

    Notice that the order in which the vertices are declared is very important. Also notice that some primitives, when given an incorrect number of vertices, will ignore any extra vertices. For example, GL_TRIANGLES only draws the triangle corresponding to vertices 1, 2, and 3. Vertices 4 and 5 are ignored.