GLBEGIN(3G)

๐Ÿ“ฆ version 24.3.3, in opensuse-leap 16.0

โœจ NAME โœจ

glBegin, glEnd โ€” bestie, these two are the little fence posts that delimit the vertices of a primitive, or a whole group of like primitives ๐Ÿ’…


๐ŸŒธ C SPECIFICATION ๐ŸŒธ

void glBegin( GLenum mode )

๐ŸŽ€ PARAMETERS ๐ŸŽ€

  • mode โ€” tells the universe which primitive (or group of like primitives) is about to be built out of all the vertices you drop between glBegin and the glEnd that follows it. You get exactly ten symbolic constants to choose from, no more no less: GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS, GL_QUAD_STRIP, and GL_POLYGON. Pick one, queen ๐Ÿ‘‘

๐ŸŒˆ C SPECIFICATION (the sequel) ๐ŸŒˆ

void glEnd( void )

๐Ÿ’– DESCRIPTION ๐Ÿ’–

So like, glBegin and glEnd are the bookends. They delimit the vertices that define a primitive, or a group of like primitives. glBegin takes one single argument, and that argument decides which of the ten possible ways your vertices get interpreted. If we say n is an integer count starting at one, and N is the total number of vertices you specified, then here's the tea, mode by mode:

  • GL_POINTS โ€” every vertex is its own little solo point. Vertex n defines point n. You get N points drawn. Main character energy, one point at a time โœจ
  • GL_LINES โ€” every pair of vertices becomes an independent line segment. Vertices 2*n*โˆ’1 and 2*n* define line n. You get N/2 lines drawn.
  • GL_LINE_STRIP โ€” a connected group of line segments running from the first vertex to the last. Vertices n and n+1 define line n. You get *N*โˆ’1 lines drawn.
  • GL_LINE_LOOP โ€” same as the strip, a connected group from the first vertex to the last, but then it loops back around to the first ๐ŸŒ€ Vertices n and n+1 define line n, except the last line is defined by vertices N and 1. You get N lines drawn.
  • GL_TRIANGLES โ€” every triplet of vertices is an independent triangle. Vertices 3*n*โˆ’2, 3*n*โˆ’1, and 3*n* define triangle n. You get N/3 triangles drawn.
  • GL_TRIANGLE_STRIP โ€” a connected group of triangles. One triangle is defined for each vertex presented after the first two vertices. For odd n, vertices n, n+1, and n+2 define triangle n. For even n, vertices n+1, n, and n+2 define triangle n (yes, the order flips, it's giving chaos but it's intentional). You get *N*โˆ’2 triangles drawn.
  • GL_TRIANGLE_FAN โ€” also a connected group of triangles, one triangle for each vertex presented after the first two. Vertices 1, n+1, and n+2 define triangle n. You get *N*โˆ’2 triangles drawn.
  • GL_QUADS โ€” every group of four vertices is an independent quadrilateral. Vertices 4*n*โˆ’3, 4*n*โˆ’2, 4*n*โˆ’1, and 4*n* define quadrilateral n. You get N/4 quadrilaterals drawn.
  • GL_QUAD_STRIP โ€” a connected group of quadrilaterals, one quadrilateral for each pair of vertices presented after the first pair. Vertices 2*n*โˆ’1, 2*n*, 2*n*+2, and 2*n*+1 define quadrilateral n. You get N/2โˆ’1 quadrilaterals drawn. โš ๏ธ Heads up bestie: the order in which vertices are used to construct a quadrilateral from strip data is different from the order used with independent data. Not a bug, just how it is.
  • GL_POLYGON โ€” one single, convex polygon. Vertices 1 through N define this polygon. Convex only, we do not do concave here ๐Ÿ’€

Now, the rules of the vibe check: only a subset of GL commands is allowed between glBegin and glEnd. That blessed list is glVertex, glColor, glIndex, glNormal, glTexCoord, glEvalCoord, glEvalPoint, glArrayElement, glMaterial, and glEdgeFlag. You're also allowed to use glCallList or glCallLists to execute display lists, as long as those display lists contain only the commands from that preceding list. If any other GL command gets executed between glBegin and glEnd, the error flag is set and the command is simply ignored. Periodt.

And regardless of which mode you picked, there is no limit to the number of vertices you can define between glBegin and glEnd. But โ€” lines, triangles, quadrilaterals, and polygons that are incompletely specified are not drawn. Incomplete specification happens when you give too few vertices to specify even a single primitive, or when you give an incorrect multiple of vertices. The incomplete primitive gets ignored; the rest are drawn. Not me leaving one triangle off the guest list ๐Ÿ˜ญ

The minimum vertex specification for each primitive is: 1 for a point, 2 for a line, 3 for a triangle, 4 for a quadrilateral, and 3 for a polygon. And the modes that demand a certain multiple of vertices are GL_LINES (2), GL_TRIANGLES (3), GL_QUADS (4), and GL_QUAD_STRIP (2). Do the math, diva ๐Ÿงฎ


๐Ÿšจ ERRORS ๐Ÿšจ

  • GL_INVALID_ENUM is generated if mode is set to an unaccepted value.
  • GL_INVALID_OPERATION is generated if glBegin is executed between a glBegin and the corresponding execution of glEnd.
  • GL_INVALID_OPERATION is generated if glEnd is executed without being preceded by a glBegin.
  • GL_INVALID_OPERATION is generated if a command other than glVertex, glColor, glIndex, glNormal, glTexCoord, glEvalCoord, glEvalPoint, glArrayElement, glMaterial, glEdgeFlag, glCallList, or glCallLists is executed between the execution of glBegin and the corresponding execution glEnd.
  • Execution of glEnableClientState, glDisableClientState, glEdgeFlagPointer, glTexCoordPointer, glColorPointer, glIndexPointer, glNormalPointer, glVertexPointer, glInterleavedArrays, or glPixelStore is not allowed after a call to glBegin and before the corresponding call to glEnd, but an error may or may not be generated. ๐Ÿ‘€ (read that again, it's a maybe, we love a grey area)

๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘

glArrayElement(3G), glCallList(3G), glCallLists(3G), glColor(3G), glEdgeFlag(3G), glEvalCoord(3G), glEvalPoint(3G), glIndex(3G), glMaterial(3G), glNormal(3G), glTexCoord(3G), glVertex(3G)


and that's the whole page, bestie ๐Ÿฆ‹ this was GLBEGIN(3G) from the 3G manual โ€” go forth and draw ur little polygons responsibly ๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from