OpenGL Rendering and State Cheat-Sheet

Here's a terse cheat-sheet that you might find useful when writing small, self-contained sequences of OpenGL rendering commands (such as those in many of the glean tests). Be sure to keep a copy of the OpenGL spec handy for detailed questions.

Quick-access index:

Operation Outline Details
Accumulation Buffer Accum({ACCUM,LOAD,RETURN,MULT}, scale)
Accum(ADD, offset)
The per-fragment operations scissor test and dithering, as well as buffer masking are applied in the case of RETURN. The scissor test applies to all accumulation operations.
Clear Buffers ClearColor(r, g, b, a)
ClearIndex(index)
ClearDepth(depth)
ClearStencil(stencil)
ClearAccum(r, g, b, a)
Clear(COLOR_BUFFER_BIT | DEPTH_BUFFER_BIT | STENCIL_BUFFER_BIT | ACCUM_BUFFER_BIT)
The per-fragment operations scissor test and dithering, as well as buffer masking are applied.
Copy Pixels ReadBuffer({FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT, FRONT, BACK, LEFT, RIGHT, AUX{0-n})
Set Common Drawing State
RasterPos{234}{sifd}[v](coords)
Set Pixel Transfer Modes
PixelZoom(zoomX, zoomY)
CopyPixels(srcX, srcY, width, height, {COLOR, STENCIL, DEPTH})
Essentially ReadPixels followed by DrawPixels, but pixel packing/unpacking is skipped and pixel transfer functions are performed only once.
Draw Geometry Set Common Drawing State
Set Rasterization Options
ShadeModel({SMOOTH,FLAT})
Specify Geometry

Draw Pixels Set Common Drawing State
RasterPos{234}{sifd}[v](coords)
Set Pixel Unpack Modes
Set Pixel Transfer Modes
PixelZoom(zoomX, zoomY)
DrawPixels(width, height, format, type, data)
Raster position is much like a vertex; is transformed, lit, used to look up a texture color, etc.

format: COLOR_INDEX, STENCIL_INDEX, DEPTH_COMPONENT, RED, GREEN, BLUE, ALPHA, RGB, RGBA, BGR, BGRA, LUMINANCE, LUMINANCE_ALPHA

type: UNSIGNED_BYTE, BITMAP, BYTE, UNSIGNED_SHORT, SHORT, UNSIGNED_INT, INT, FLOAT, UNSIGNED_BYTE_3_3_2, UNSIGNED_BYTE_2_3_3_REV, UNSIGNED_SHORT_5_6_5, UNSIGNED_SHORT_5_6_5_REV, UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_4_4_4_4_REV, UNSIGNED_SHORT_5_5_5_1, UNSIGNED_SHORT_1_5_5_5_REV, UNSIGNED_INT_8_8_8_8, UNSIGNED_INT_8_8_8_8_REV, UNSIGNED_INT_10_10_10_2, UNSIGNED_INT_2_10_10_10_REV

Packed types place first component in most-significant bits of storage unit; REV packed types reverse the order.

Load Texture Image Set Pixel Unpack Modes
Set Pixel Transfer Modes
TexImage2D(TEXTURE_2D, mipmapLevel, internalFormat, width, height, border, format, type, data)

Set Pixel Unpack Modes
Set Pixel Transfer Modes
TexSubImage2D(TEXTURE_2D, mipmapLevel, texXOffset, texYOffset, width, height, format, type, data)

Set Pixel Transfer Modes
CopyTexImage2D(TEXTURE_2D, mipmapLevel, internalFormat, fbX, fbY, width, height, border)

Set Pixel Transfer Modes
CopyTexSubImage2D(TEXTURE_2D, mipmapLevel, texXOffset, texYOffset, fbX, fbY, width, height)
internalFormat: ALPHA{,4,8,12,16}, LUMINANCE{,4,8,12,16}, LUMINANCE4_ALPHA4, LUMINANCE6_ALPHA2, LUMINANCE8_ALPHA8, LUMINANCE12_ALPHA4, LUMINANCE12_ALPHA12, LUMINANCE16_ALPHA16, INTENSITY{,4,8,12,16}, RGB{,4,5,8,10,12,16}, R3_G3_B2, RGBA{,2,4,8,12,16}, RGB5_A1, RGB10_A2

format, type: See Draw Pixels.

level is 0 for the highest-resolution mipmap level.

border might as well always be 0.

Matrix Operations LoadIdentity()
LoadMatrix(m)
MultMatrix(m)
Rotate{fd}(degrees, x, y, z)
Translate{fd}(x, y, z)
Scale{fd}(x, y, z)
Frustum(l, r, b, t, n, f) (n, f > 0)
Ortho(l, r, b, t, n, f)
Matrix element order is (Sxx, Sxy, Sxz, Sxw, Syx, Syy, Syz, Syw, Szx, Szy, Szz, Szw, Tx, Ty, Tz, 1). Spq means the scale factor applied to input coordinate p that contributes to output coordinate q. Tp means translation along coordinate p.

Use right-hand rule to find sense of rotation.

Near/far values are distances from the eye.

Read Pixels Set Pixel Pack Modes
Set Pixel Transfer Modes ReadBuffer({FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT, FRONT, BACK, LEFT, RIGHT, AUX{0-n}) ReadPixels(x, y, width, height, format, type, data)
For format and type, see Draw Pixels.
Select/Mask Buffers DrawBuffer({NONE, FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT, FRONT, BACK, LEFT, RIGHT, FRONT_AND_BACK, AUX{0-?})
IndexMask(uint mask)
ColorMask(boolean r, g, b, a)
DepthMask(boolean)
StencilMask(uint mask)

Set Common Drawing State Set Viewport and Projection
Set Lighting Parameters
Set Material Parameters
Set ModelView
Set Texturing
Set Extra Clip Planes
Set Fog Parameters
Set Per-Fragment Operations
Select/Mask Buffers

Set Extra Clip Planes ClipPlane(CLIP_PLANE{0-5}, eqn)
Enable/Disable(CLIP_PLANE{0-5})
eqn has plane eqn coefs, in object coords.
Set Fog Parameters Fog{if}[v](name, param)
Enable/Disable(FOG)
NameParam
FOG_MODE EXP, EXP2, LINEAR
FOG_DENSITY float (density for EXP, EXP2)
FOG_START float (eye coord distance to fog start, for LINEAR)
FOG_END float (eye coord distance to fog end, for LINEAR)
FOG_COLOR 4 floats (fog fade color, for LINEAR)
Set Light Model Parameters
LightModel{if}[v](name, param)
NameValues
LIGHT_MODEL_AMBIENT4
LIGHT_MODEL_LOCAL_VIEWER1 (bool)
LIGHT_MODEL_TWO_SIDE1 (bool)
LIGHT_MODEL_COLOR_CONTROL1

LIGHT_MODEL_COLOR_CONTROL: SINGLE_COLOR, SEPARATE_SPECULAR_COLOR
Set Light Source Parameters Set Modelview
Light{if}[v](LIGHT{0-7}, name, param)
Enable/Disable(LIGHT{0-7})
NameValues
AMBIENT4
DIFFUSE4
SPECULAR4
POSITION4 (homogeneous)
SPOT_DIRECTION3
SPOT_EXPONENT1
SPOT_CUTOFF1
CONSTANT_ATTENUATION1
LINEAR_ATTENUATION1
QUADRATIC_ATTENUATION1
Set Lighting Parameters Set Light Source Parameters
Set Light Model Parameters
Enable/Disable(LIGHTING)

Set Material Parameters FrontFace({CCW, CW})
Enable/Disable(NORMALIZE)
Material{if}[v](face, name, param)
ColorMaterial(face, mode)
Enable/Disable(COLOR_MATERIAL)
face: FRONT, BACK, FRONT_AND_BACK

NameValues
AMBIENT4
DIFFUSE4
AMBIENT_AND_DIFFUSE4
SPECULAR4
EMISSION4
SHININESS1
COLOR_INDEXES3 (a, d, s)

mode: EMISSION, AMBIENT, DIFFUSE, SPECULAR, AMBIENT_AND_DIFFUSE

Set ModelView MatrixMode(MODELVIEW)
Matrix Operations

Set Per-Fragment Operations Scissor(left, bottom, width, height)
Enable/Disable(SCISSOR_TEST)
AlphaFunc(aFunc, float refValue)
Enable/Disable(ALPHA_TEST)
StencilFunc(sFunc, int refValue, uint mask)
StencilOp(sFail, dFail, dPass)
Enable/Disable(STENCIL_TEST)
DepthFunc(dFunc)
Enable/Disable(DEPTH_TEST)
BlendColor(r, g, b, a) (imaging subset)
BlendEquation(bEqn) (imaging subset)
BlendFunc(src, dst)
Enable/Disable(BLEND)
Enable/Disable(DITHER)
LogicOp(op)
Enable/Disable(INDEX_LOGIC_OP)
Enable/Disable(COLOR_LOGIC_OP)
aFunc, sFunc, dFunc: NEVER, ALWAYS, LESS, LEQUAL, EQUAL, GEQUAL, GREATER, NOTEQUAL

sFail, dFail, dPass: KEEP, ZERO, REPLACE, INCR, DECR, INVERT

bEqn: FUNC_ADD, FUNC_SUBTRACT, FUNC_REVERSE_SUBTRACT, MIN, MAX

src: ZERO, ONE, DST_COLOR, ONE_MINUS_DST_COLOR, SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR, CONSTANT_ALPHA, ONE_MINUS_CONSTANT_ALPHA, SRC_ALPHA_SATURATE

dst: ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR, CONSTANT_ALPHA, ONE_MINUS_CONSTANT_ALPHA

op: CLEAR, AND, AND_REVERSE, COPY, AND_INVERTED, NOOP, XOR, OR, NOR, EQUIV, INVERT, OR_REVERSE, COPY_INVERTED, OR_INVERTED, NAND, SET

Set Pixel Pack Modes PixelStore{if}(name, param)
NameValid Range
PACK_SWAP_BYTESTRUE/FALSE
PACK_LSB_FIRSTTRUE/FALSE
PACK_ROW_LENGTH>=0
PACK_SKIP_ROWS>=0
PACK_SKIP_PIXELS>=0
PACK_ALIGNMENT1,2,4,8
PACK_IMAGE_HEIGHT>=0
PACK_SKIP_IMAGES>=0
Set Pixel Transfer Modes PixelTransfer{if}(name, param)
PixelMap{ui,us,f}v(mapName, mapSize, mapValues)

Imaging subset commands omitted for brevity

rgba indicates a choice of RED, GREEN, BLUE, or ALPHA.
NameType
MAP_COLOR Boolean
MAP_STENCIL Boolean
INDEX_SHIFT int
INDEX_OFFSET int
rgba_SCALE float
DEPTH_SCALE float
rgba_BIAS float
DEPTH_BIAS float

mapName: PIXEL_MAP_{I_TO_I, S_TO_S, I_TO_R, I_TO_G, I_TO_B, I_TO_A, R_TO_R, G_TO_G, B_TO_B, A_TO_A

Set Pixel Unpack Modes PixelStore{if}(name, param)
NameValid Range
UNPACK_SWAP_BYTESTRUE/FALSE
UNPACK_LSB_FIRSTTRUE/FALSE
UNPACK_ROW_LENGTH>=0
UNPACK_SKIP_ROWS>=0
UNPACK_SKIP_PIXELS>=0
UNPACK_ALIGNMENT1,2,4,8
UNPACK_IMAGE_HEIGHT>=0
UNPACK_SKIP_IMAGES>=0
Set Rasterization Options PointSize(size)
Enable/Disable(POINT_SMOOTH)
LineWidth(width)
Enable/Disable(LINE_SMOOTH)
LineStipple(int repeatCount, ushort bitPattern)
Enable/Disable(LINE_STIPPLE)
PolygonMode({FRONT,BACK,FRONT_AND_BACK},
  {POINT,LINE,FILL})

CullFace({FRONT,BACK,FRONT_AND_BACK})
Enable/Disable(CULL_FACE)
PolygonStipple(ubyte* pattern)
Enable/Disable(POLYGON_STIPPLE)
PolygonOffset(factor, offset)
Enable/Disable(POLYGON_OFFSET_{POINT,LINE,FILL})
See DrawPixels for stipple pattern (32x32 bitmap) unpacking rules.
Set TexGen
TexGen{ifd}[v]( {S,T,R,Q}, name, param)
Enable/Disable(TEXTURE_GEN_{S,T,R,Q})
Name Param
TEXTURE_GEN_MODE OBJECT_LINEAR, EYE_LINEAR, SPHERE_MAP
OBJECT_PLANE Plane eqn coefs for OBJECT_LINEAR, obj coords
EYE_PLANE Plane eqn coefs for EYE_LINEAR, eye coords
Set Texture Environment TexEnv{if}[v](TEXTURE_ENV, name, param)
NameParam
TEXTURE_ENV_MODE REPLACE, MODULATE, DECAL, BLEND
TEXTURE_ENV_COLOR r, g, b, a
Set Texture Parameters TexParameter{if}[v](TEXTURE_{123}D, name, param)
NameParam
TEXTURE_WRAP_S CLAMP, CLAMP_TO_EDGE, REPEAT
TEXTURE_WRAP_T CLAMP, CLAMP_TO_EDGE, REPEAT
TEXTURE_WRAP_R CLAMP, CLAMP_TO_EDGE, REPEAT
TEXTURE_MIN_FILTER NEAREST, LINEAR, NEAREST_MIPMAP_NEAREST, NEAREST_MIPMAP_LINEAR, LINEAR_MIPMAP_NEAREST, LINEAR_MIPMAP_LINEAR
TEXTURE_MAG_FILTER NEAREST, LINEAR
TEXTURE_BORDER_COLOR 4 floats in [0,1]
TEXTURE_PRIORITY float in [0,1]
TEXTURE_MIN_LOD float (LOD range clamp)
TEXTURE_MAX_LOD float (LOD range clamp)
TEXTURE_BASE_LEVEL int (level residence clamp)
TEXTURE_MAX_LEVEL int (level residence clamp)
Set Texturing BindTexture(TEXTURE_2D, textureID)
Load Texture Image if needed
Set Texture Parameters
Set Texture Environment
MatrixMode(TEXTURE)
Matrix Operations
Set TexGen
Enable/Disable(TEXTURE_2D)
1D and 3D textures omitted for brevity
Set Viewport and Projection Viewport(x, y, w, h)
DepthRange(n, f) (n, f in [0,1])
MatrixMode(PROJECTION)
Matrix Operations
Lower-left corner of projected view volume maps to window coords (x,y).
Specify Geometry Begin/End
Vertex Arrays
Display Lists
Vertices in clockwise order
Vertex Arrays TexCoordPointer(e, t, s, p)
Enable/DisableClientState(TEXTURE_COORD_ARRAY)
ColorPointer(e, t, s, p)
Enable/DisableClientState(COLOR_ARRAY)
NormalPointer(t, s, p)
Enable/DisableClientState(NORMAL_ARRAY)
VertexPointer(e, t, s, p)
Enable/DisableClientState(VERTEX_ARRAY)
Begin/ArrayElement(i)/End
or DrawArrays(prim, first, count)
or DrawElements(prim, count, uit, indices)
e = number of elements (1-4)
t = type (SHORT, INT, etc.)
s = stride in bytes
p = pointer to data
uit = any unsigned int type
indices = pointer to array of indices

InterleavedArrays can be used for easy setup of a few selected vertex formats.

See also compiled vertex arrays.

Things not yet covered: