CPEN 461/661, Spring 1997
OpenGL Tutorial

  1. OpenGL Primitives
  2. The programmer is provided the following primitives for use inconstructing geometric objects.



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

    With OpenGL, all geometric objects are ultimately described as anordered set of vertices. The command glVertex*()is used to specify a vertex. Here are some example uses of glVertex*():

    	glVertex2s(1, 2);	glVertex3d(0.0, 0.0, 3.1415926535898);	glVertex4f(1.3, 2.0, -4.2, 1.0);	GLdouble vector[3] = {3.0, 10.0 2033.0};	glVertex3dv(vector);

    All calls to glVertex*()should occur between a glBegin() andglEnd()pair. Drawing occurs each time a glBegin() andglEnd()pair is reached with the exception of display lists which are coveredin the section Display Lists ofthe tutorial.

    It is important to note that OpenGL commands are not necessarilyexecuted as soon as they are issued. It is necessary to call thecommand glFlush() toensure that all previously issued commands are executed. glFlush()isgenerally called at the end of a sequence of drawing commands to ensureall objects in the scene are drawn.

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

    Primitives.c Output



    primitives.c Source Code

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