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.
Packed types place first component in most-significant bits
of storage unit; |
||||||||||||||||||||||||
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
|
||||||||||||||||||||||||
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)
|
|
||||||||||||||||||||||||
Set Light Model Parameters |
LightModel{if}[v](name, param)
|
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})
|
|
||||||||||||||||||||||||
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
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
|
||||||||||||||||||||||||
Set Pixel Pack Modes |
PixelStore{if}(name, param)
|
|
||||||||||||||||||||||||
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 .
|
||||||||||||||||||||||||
Set Pixel Unpack Modes |
PixelStore{if}(name, param)
|
|
||||||||||||||||||||||||
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},
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})
|
|
||||||||||||||||||||||||
Set Texture Environment | TexEnv{if}[v](TEXTURE_ENV, name, param)
|
|
||||||||||||||||||||||||
Set Texture Parameters | TexParameter{if}[v](TEXTURE_{123}D, name, param)
|
|
||||||||||||||||||||||||
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
See also compiled vertex arrays. |
Things not yet covered: