Home > Articles > Programming > Graphic Programming

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

A 3D Point: The Vertex

To specify a drawing point in this 3D "palette," we use the OpenGL function glVertex—without a doubt the most used function in all the OpenGL API. This is the "lowest common denominator" of all the OpenGL primitives: a single point in space. The glVertex function can take from one to four parameters of any numerical type, from bytes to doubles, subject to the naming conventions discussed in Chapter 2, "Using OpenGL."

The following single line of code specifies a point in our coordinate system located 50 units along the x-axis, 50 units along the y-axis, and 0 units out the z-axis:

glVertex3f(50.0f, 50.0f, 0.0f);

Figure 3.2 illustrates this point. Here, we chose to represent the coordinates as floating-point values, as we do for the remainder of the book. Also, the form of glVertex that we use takes three arguments for the x, y, and z coordinate values, respectively.

Figure 3.2Figure 3.2 The point (50,50,0) as specified by glVertex3f(50.0f, 50.0f, 0.0f).

Two other forms of glVertex take two and four arguments, respectively. We can represent the same point in Figure 3.2 with this code:

glVertex2f(50.0f, 50.0f);

This form of glVertex takes only two arguments that specify the x and y values and assumes the z coordinate to be 0.0 always.

The form of glVertex taking four arguments, glVertex4, uses a fourth coordinate value w (set to 1.0 by default when not specified) for scaling purposes. You will learn more about this coordinate in Chapter 4 when we spend more time exploring coordinate transformations.

  • + Share This
  • 🔖 Save To Your Account