Notes

Thoughts, write-ups, and things worth remembering.

OpenGL API naming and call order

#graphics#opengl Updated Oct 13, 2026

gl function names are verb + object, with a type suffix. Call order only matters where one call reads state another call sets.

Reading a function name

PieceMeaningExample
glGen*Allocate several, handles written through a pointerglGenBuffers(1, &buf)
glCreate*Allocate one, handle returnedglCreateShader(GL_VERTEX_SHADER)
glBind*Put an object into a slotglBindBuffer
gl*DataUpload into the bound objectglBufferData
glGet*LocationFind a shader variable’s index by nameglGetUniformLocation
glUniform*Set a uniform on the current programglUniform1f
glUse*Pick the active programglUseProgram
glDraw*Run the pipelineglDrawElements
SuffixCount + type; v = pass a pointer2i two ints, Matrix3fv

Order: what must come first

FirstThenWhy
glUseProgramglUniform*Uniforms belong to the current program
glBindBuffer(ARRAY)glVertexAttribPointerPointer wires the buffer bound at that moment
glBindBuffer(ELEMENT_ARRAY)glDrawElementsDraw reads indices from that slot
All setupglDrawElementsThe draw uses whatever state exists right then
glDrawElementsglDisableVertexAttribArrayClose the input after use

Calls with no dependency can swap freely (Enable vs Pointer, uniforms vs vertex wiring).

Each draw sets up its own state instead of relying on what init left behind, since other code and other objects change bindings in between.

The three counts

glBufferData(
    target,
    BYTES,                  // total bytes: count * sizeof(element)
    ptr,
    usage);

glVertexAttribPointer(
    loc,
    COMPONENTS_PER_VERTEX,  // 3 for vec3
    GL_FLOAT,
    GL_FALSE,
    STRIDE_BYTES,           // 0 = tightly packed
    OFFSET);                // nullptr = start of buffer

glDrawElements(
    GL_TRIANGLES,
    INDEX_COUNT,            // total indices, 3 per triangle
    GL_UNSIGNED_INT,
    nullptr);

glEnableVertexAttribArray is off by default. When off, every vertex reads one constant value instead of the buffer.

Matrix uniform

glUniformMatrix3fv(loc, 1, GL_FALSE, glm::value_ptr(model)); // or &model[0][0]
  • 1: number of matrices (arrays of mat3 can take more).
  • GL_FALSE: no transpose. glm and GL are both column-major.
  • Pointer: GL reads 9 contiguous floats from there.
  • T, R, S are multiplied into one matrix on the CPU; the shader multiplies once per vertex.

OpenGL Hub · OpenGL handles and state machine · Matrix composition order (SRT)