Show Menu

WebGL-BasicFunctions Cheat Sheet (DRAFT) by

This is a very simple cheatsheet about webgl most common functions.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Buffer Objects

Creates a new buffer object: Object create­Buf­fer() Note: Corres­ponding OpenGL ES function is GenBuffers
Binds an empty array buffer to the object: void bindBu­ffe­r(enum target, Object buffer) target: ARRAY_­BUFFER, ELEMEN­T_A­RRA­Y_B­UFFER
Assings the passed values to the target: void buffer­Dat­a(enum target, Object data, enum usage) target and usage: Same as for bufferData above

Uniforms and Attributes

Index of the attributeulong getAtt­rib­Loc­ati­on(­Object program, string name)
Index of the uniform variable: uint getUni­for­mLo­cat­ion­(Object program, string name)
Passes the inform­ation from buffer to attribute: void vertex­Att­rib­Poi­nte­r(uint index, int size, enum type, bool normal­ized, long stride, long offset) type: BYTE, SHORT, UNSIGN­ED_­{BYTE, SHORT}, FIXED, FLOAT index: [0, MAX_VE­RTE­X_A­TTRIBS - 1] stride: [0, 255] offset, stride: must be a multiple of the type size in WebGL

Storage Qualifiers

attribute : Linkage between a vertex shader and OpenGL ES for per-vertex data
uniform : Value does not change across the primitive being processed, uniforms form the linkage between a shader, OpenGL ES, and the applic­ation
varying : Linkage between a vertex shader and fragment shader for interp­olated data

Programs and shaders

Creates a shader object: Object create­Sha­der­(enum type) type: VERTEX­_SH­ADER, FRAGME­NT_­SHADER
Creates a program:Object create­Pro­gram()
Assigns a source program to the object: ** void shader­Sou­rce­(Object shader, string source)
Attach the shader to the program:void attach­Sha­der­(Object program, Object shader)
Compiles the shader: void compil­eSh­ade­r(O­bject shader)
Links the attached shadersvoid linkPr­ogr­am(­Object program)
Uses the combined shaders:void usePro­gra­m(O­bject program)

Writing to the draw buffer

Draws the given array: void drawAr­ray­s(enum mode, int first, long count) mode: POINTS, LINE_S­TRIP, LINE_LOOP, LINES, TRIANG­LE_­STRIP, TRIANG­LE_FAN, TRIANGLES first: May not be a negative value.
Draws the passed element void drawEl­eme­nts­(enum mode, long count, enum type, long offset) mode: POINTS, LINE_S­TRIP, LINE_LOOP, LINES, TRIANG­LE_­STRIP, TRIANG­LE_FAN, TRIANGLES type: UNSIGN­ED_­BYTE, UNSIGN­ED_­SHORT


highp : Satisfies minimum requir­ements for the vertex language. Optional in the fragment language.
mediump: Satisfies minimum requir­ements for the fragment language. Its range and precision is between that provided by lowp and highp.
lowp: Range and precision can be less than mediump, but still represents all color values for any color channel.