GLBEGIN(3G)
โจ 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 betweenglBeginand theglEndthat 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, andGL_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_ENUMis generated ifmodeis set to an unaccepted value.GL_INVALID_OPERATIONis generated ifglBeginis executed between aglBeginand the corresponding execution ofglEnd.GL_INVALID_OPERATIONis generated ifglEndis executed without being preceded by aglBegin.GL_INVALID_OPERATIONis generated if a command other thanglVertex,glColor,glIndex,glNormal,glTexCoord,glEvalCoord,glEvalPoint,glArrayElement,glMaterial,glEdgeFlag,glCallList, orglCallListsis executed between the execution ofglBeginand the corresponding executionglEnd.- Execution of
glEnableClientState,glDisableClientState,glEdgeFlagPointer,glTexCoordPointer,glColorPointer,glIndexPointer,glNormalPointer,glVertexPointer,glInterleavedArrays, orglPixelStoreis not allowed after a call toglBeginand before the corresponding call toglEnd, 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
- centos-stream 9: gl-manpages 1.1-24.20190306.el9 ยท MIT and Open Publication
- fedora 43: gl-manpages 1.1-34.20190306.fc43 ยท Apache-2.0 AND HPND AND HPND-sell-variant AND MIT AND OpenPBS-2.3 AND SGI-B-2.0 AND W3C-19980720 AND X11
- fedora 44: gl-manpages 1.1-35.20190306.fc44 ยท Apache-2.0 AND HPND AND HPND-sell-variant AND MIT AND OpenPBS-2.3 AND SGI-B-2.0 AND W3C-19980720 AND X11
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms