Skip to main content

OpenGL syntax: 3D vertex

Short answer

Specify a 3D float vertex with glVertex3f(x, y, z) inside glBegin/glEnd. The command name indicates library 'gl', command 'Vertex', 3 coordinates, and float type ('f'); the 'v' version (e.g., glVertex3fv) takes an array pointer.

Explain OpenGL syntax to draw a three dimensional, floating point vectored vertex.

A three-dimensional vertex with floating-point coordinates is specified with the glVertex3f command. In the OpenGL command name glVertex3f:

  • gl is the library prefix, Vertex the command, 3 the number of coordinates (x, y, z), and f the data type (float; d = double, i = int, s = short).
  • Adding v (as in glVertex3fv) means the argument is a pointer to an array (a vector).

Syntax

void glVertex3f(GLfloat x, GLfloat y, GLfloat z);
void glVertex3fv(const GLfloat *v);

Example

GLfloat p[3] = {1.0f, 2.5f, -3.0f};

glBegin(GL_POINTS);
    glVertex3f(0.5f, 0.5f, 0.0f);   // separate values
    glVertex3fv(p);                  // using an array (vector form)
glEnd();

A vertex call must appear between glBegin() and glEnd(). If a four-coordinate form glVertex4f(x, y, z, w) is used, w is the homogeneous coordinate (1.0 by default in the 3-coordinate form).

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Graphics chapter 9 questions →