Legacy (immediate mode)GL 1.0

glBegin

Starts sending vertices one by one from the CPU (immediate mode).

Removed from the core profile. Part of the legacy immediate mode, removed from the core profile in OpenGL 3.2. Shown here only so you can recognize it in old tutorials — use VBOs and VAOs instead.

Signature

void glBegin(GLenum mode);

How it works

In immediate mode, each vertex was a separate function call between glBegin and glEnd. For a mesh with a million vertices that is millions of calls from CPU to driver every frame — the bottleneck that buffers were invented to remove. In modern OpenGL the same data lives in a VBO on the GPU and one draw call renders it.

Parameters

modeGLenum

Primitive type: GL_TRIANGLES, GL_QUADS (also removed), GL_LINES…

Example

example.cpp
1// Legacy — does not work in a core profile context
2glBegin(GL_TRIANGLES);
3    glColor3f(1, 0, 0); glVertex3f(-0.5f, -0.5f, 0);
4    glColor3f(0, 1, 0); glVertex3f( 0.5f, -0.5f, 0);
5    glColor3f(0, 0, 1); glVertex3f( 0.0f,  0.5f, 0);
6glEnd();