- 2069 Asar · 4 marks
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:
glis the library prefix,Vertexthe command,3the number of coordinates (x, y, z), andfthe data type (float;d= double,i= int,s= short).- Adding
v(as inglVertex3fv) 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)
Related questions
- OpenGL syntax: parallelogram · Computer Graphics, chapter 9
- 3D scaling about arbitrary point · Computer Graphics, chapter 4
- Drawing primitives in OpenGL · Computer Graphics, chapter 9 · asked 4×
- Boundary representation of 3D objects · Computer Graphics, chapter 6 · asked 4×
- 3D world to viewing coordinate matrix · Computer Graphics, chapter 4 · asked 2×
- Floating point addition and subtraction · Computer Organization and Architecture, chapter 5 · asked 6×
- Floating point division algorithm · Computer Organization and Architecture, chapter 5 · asked 4×
- Floating point multiplication · Computer Organization and Architecture, chapter 5 · asked 3×
- Parametric line in 3D: point and plane intersection · Computer Aided Design, chapter 3