Stdlib gl
The gl module provides OpenGL bindings for 3D graphics rendering. It exposes a comprehensive set of OpenGL functions and constants for creating 3D applications with immediate mode rendering, display lists, vertex arrays, lighting, texturing, and more.
Initialization
init()
Initializes OpenGL context.
- Returns:
null - Example:
gl.init()
Matrix Operations
matrix_mode(mode)
Sets the current matrix mode.
- Parameters:
mode- Matrix mode constant (gl.MODELVIEW,gl.PROJECTION, orgl.TEXTURE)- Returns:
null - Example:
gl.matrix_mode(gl.PROJECTION)
load_identity()
Replaces the current matrix with the identity matrix.
- Returns:
null - Example:
gl.load_identity()
push_matrix()
Pushes the current matrix stack.
- Returns:
null - Example:
gl.push_matrix()
pop_matrix()
Pops the current matrix stack.
- Returns:
null - Example:
gl.pop_matrix()
mult_matrixf(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15)
Multiplies the current matrix by a 4x4 matrix.
- Parameters: 16 float values in column-major order
- Returns:
null - Example:
go gl.mult_matrixf(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
load_matrixf(m0, m1, ... m15)
Replaces the current matrix with a 4x4 matrix.
- Parameters: 16 float values in column-major order
- Returns:
null
translatef(x, y, z)
Multiplies the current matrix by a translation matrix.
- Parameters:
x,y,z- Translation values (float) - Returns:
null - Example:
gl.translatef(1.0, 2.0, 3.0)
rotatef(angle, x, y, z)
Multiplies the current matrix by a rotation matrix.
- Parameters:
angle- Rotation angle in degrees,x,y,z- Rotation axis - Returns:
null - Example:
gl.rotatef(45.0, 0.0, 1.0, 0.0)
scalef(x, y, z)
Multiplies the current matrix by a scaling matrix.
- Parameters:
x,y,z- Scale factors (float) - Returns:
null - Example:
gl.scalef(2.0, 2.0, 2.0)
ortho(left, right, bottom, top, zNear, zFar)
Multiplies the current matrix by an orthographic projection matrix.
- Parameters:
left,right- Left and right clipping planes (float)bottom,top- Bottom and top clipping planes (float)zNear,zFar- Near and far clipping planes (float)- Returns:
null - Example:
gl.ortho(-1, 1, -1, 1, -1, 1)
frustum(left, right, bottom, top, zNear, zFar)
Multiplies the current matrix by a perspective projection matrix.
- Parameters:
left,right- Left and right clipping planes (float)bottom,top- Bottom and top clipping planes (float)zNear,zFar- Near and far clipping planes (float, must be positive)- Returns:
null - Example:
gl.frustum(-1, 1, -1, 1, 1, 100)
Viewport and Scissor
viewport(x, y, width, height)
Sets the viewport.
- Parameters:
x,y- Lower-left corner,width,height- Viewport dimensions (int) - Returns:
null - Example:
gl.viewport(0, 0, 800, 600)
scissor(x, y, width, height)
Sets the scissor rectangle.
- Parameters:
x,y- Lower-left corner,width,height- Rectangle dimensions (int) - Returns:
null
Clearing
clear(mask)
Clears buffers.
- Parameters:
mask- Bitwise OR of clear bits (gl.COLOR_BUFFER_BIT,gl.DEPTH_BUFFER_BIT,gl.STENCIL_BUFFER_BIT) - Returns:
null - Example:
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
clear_color(r, g, b, a)
Sets the color buffer clear value.
- Parameters:
r,g,b,a- Color components (float, 0.0-1.0) - Returns:
null - Example:
gl.clear_color(0.2, 0.3, 0.4, 1.0)
clear_depth(depth)
Sets the depth buffer clear value.
- Parameters:
depth- Depth value (float) - Returns:
null
clear_stencil(s)
Sets the stencil buffer clear value.
- Parameters:
s- Stencil value (int) - Returns:
null
clear_accum(r, g, b, a)
Sets the accumulation buffer clear value.
- Parameters:
r,g,b,a- Color components (float) - Returns:
null
Primitives
begin(mode)
Begins a primitive drawing mode.
- Parameters:
mode- Primitive type (gl.POINTS,gl.LINES,gl.TRIANGLES,gl.QUADS, etc.) - Returns:
null - Example:
go gl.begin(gl.TRIANGLES) gl.vertex3f(0, 1, 0) gl.vertex3f(-1, -1, 0) gl.vertex3f(1, -1, 0) gl.end()
end()
Ends a primitive drawing mode.
- Returns:
null
vertex2f(x, y)
vertex3f(x, y, z)
vertex4f(x, y, z, w)
vertex2d(x, y)
vertex3d(x, y, z)
vertex4d(x, y, z, w)
vertex2i(x, y)
vertex3i(x, y, z)
Specifies a vertex (float, double, or integer versions).
- Returns:
null
Colors
color3f(r, g, b)
color4f(r, g, b, a)
color3ub(r, g, b)
color4ub(r, g, b, a)
Sets the current color (float or unsigned byte versions).
- Parameters: Color components (float: 0.0-1.0, byte: 0-255)
- Returns:
null - Example:
gl.color3f(1.0, 0.0, 0.0)
Normals
normal3f(nx, ny, nz)
Sets the current normal vector.
- Parameters:
nx,ny,nz- Normal components (float) - Returns:
null - Example:
gl.normal3f(0.0, 0.0, 1.0)
Texture Coordinates
tex_coord2f(s, t)
Sets the current texture coordinates.
- Parameters:
s,t- Texture coordinates (float) - Returns:
null - Example:
gl.tex_coord2f(0.5, 0.5)
Enable/Disable
enable(cap)
disable(cap)
is_enabled(cap)
Enables, disables, or checks OpenGL capabilities.
- Parameters:
cap- Capability constant (gl.BLEND,gl.DEPTH_TEST,gl.LIGHTING, etc.) - Returns:
nullforenable/disable,boolforis_enabled - Example:
gl.enable(gl.DEPTH_TEST)
Blending
blend_func(sfactor, dfactor)
Sets the pixel blending function.
- Parameters:
sfactor- Source factor,dfactor- Destination factor - Returns:
null - Example:
gl.blend_func(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
blend_equation(mode)
Sets the blend equation.
- Parameters:
mode- Blend equation (gl.FUNC_ADD,gl.FUNC_SUBTRACT, etc.) - Returns:
null
blend_color(r, g, b, a)
Sets the blend color.
- Parameters:
r,g,b,a- Color components (float) - Returns:
null
Depth Test
depth_func(func)
Sets the depth test function.
- Parameters:
func- Depth function (gl.LESS,gl.LEQUAL,gl.GEQUAL, etc.) - Returns:
null - Example:
gl.depth_func(gl.LESS)
depth_mask(flag)
Enables or disables depth buffer writing.
- Parameters:
flag- Boolean or integer - Returns:
null
depth_range(near, far)
Sets the depth range.
- Parameters:
near,far- Depth range values (float) - Returns:
null
Alpha Test
alpha_func(func, ref)
Sets the alpha test function.
- Parameters:
func- Alpha function,ref- Reference value (float) - Returns:
null
Culling
cull_face(mode)
Specifies which faces to cull.
- Parameters:
mode-gl.FRONT,gl.BACK, orgl.FRONT_AND_BACK - Returns:
null - Example:
gl.cull_face(gl.BACK)
front_face(mode)
Sets which face is considered front-facing.
- Parameters:
mode-gl.CW(clockwise) orgl.CCW(counter-clockwise) - Returns:
null
Polygon Modes
polygon_mode(face, mode)
Sets the polygon rendering mode.
- Parameters:
face-gl.FRONT_AND_BACK,mode-gl.POINT,gl.LINE, orgl.FILL - Returns:
null
polygon_offset(factor, units)
Sets the polygon offset.
- Parameters:
factor,units- Offset values (float) - Returns:
null
Line & Point Sizes
line_width(width)
Sets the line width.
- Parameters:
width- Line width (float) - Returns:
null
point_size(size)
Sets the point size.
- Parameters:
size- Point size (float) - Returns:
null
Stencil
stencil_func(func, ref, mask)
Sets the stencil test function.
- Parameters:
func- Stencil function,ref- Reference value (int),mask- Mask (uint) - Returns:
null
stencil_mask(mask)
Sets the stencil write mask.
- Parameters:
mask- Mask value (uint) - Returns:
null
stencil_op(fail, zfail, zpass)
Sets the stencil operation.
- Parameters:
fail- Operation on stencil test failure,zfail- Operation on depth test failure,zpass- Operation on depth test pass - Returns:
null
State Saving
push_attrib(mask)
pop_attrib()
Pushes and pops attribute stack.
- Parameters:
mask- Attribute mask (uint) - Returns:
null
push_client_attrib(mask)
pop_client_attrib()
Pushes and pops client attribute stack.
- Parameters:
mask- Client attribute mask (uint) - Returns:
null
Shading
shade_model(mode)
Sets the shading model.
- Parameters:
mode-gl.FLATorgl.SMOOTH - Returns:
null
Hints
hint(target, mode)
Sets hint parameters.
- Parameters:
target- Hint target,mode-gl.DONT_CARE,gl.FASTEST, orgl.NICEST - Returns:
null
Lighting
lightf(light, pname, param)
lighti(light, pname, param)
lightfv(light, pname, ...params)
Sets light source parameters (float, int, or array versions).
- Parameters:
light- Light number (gl.LIGHT0,gl.LIGHT1, etc.),pname- Parameter name,param(s)- Parameter value(s) - Returns:
null - Example:
go gl.lightfv(gl.LIGHT0, gl.POSITION, 1.0, 1.0, 1.0, 0.0) gl.lightf(gl.LIGHT0, gl.SPOT_CUTOFF, 45.0)
light_modelf(pname, param)
light_modeli(pname, param)
Sets lighting model parameters.
- Returns:
null
materialf(face, pname, param)
materialfv(face, pname, ...params)
Sets material parameters.
- Parameters:
face-gl.FRONT,gl.BACK, orgl.FRONT_AND_BACK - Returns:
null - Example:
gl.materialfv(gl.FRONT_AND_BACK, gl.SPECULAR, 0.8, 0.8, 0.8, 1.0)
color_material(face, mode)
Makes material colors track the current color.
- Parameters:
face-gl.FRONT,gl.BACK, orgl.FRONT_AND_BACKmode- Which material parameters to track (gl.AMBIENT,gl.DIFFUSE,gl.SPECULAR, etc.)- Returns:
null - Example:
gl.color_material(gl.FRONT_AND_BACK, gl.DIFFUSE)
Fog
fogf(pname, param)
fogfv(pname, ...params)
Sets fog parameters.
- Parameters:
pname- Parameter name (gl.FOG_COLOR,gl.FOG_DENSITY, etc.) - Returns:
null - Example:
go gl.fogf(gl.FOG_DENSITY, 0.05) gl.fogfv(gl.FOG_COLOR, 0.5, 0.5, 0.5, 1.0)
Textures
gen_textures(n)
Generates texture names.
- Parameters:
n- Number of textures to generate (int) - Returns: Array of texture IDs
- Example:
textures := gl.gen_textures(1)
bind_texture(target, texture)
Binds a named texture.
- Parameters:
target-gl.TEXTURE_2D,gl.TEXTURE_CUBE_MAP, etc.,texture- Texture ID - Returns:
null - Example:
gl.bind_texture(gl.TEXTURE_2D, textures[0])
delete_textures(textures)
Deletes named textures.
- Parameters:
textures- Single texture ID or array of texture IDs - Returns:
null
tex_image1d(target, level, internal_format, width, border, format, type, pixels)
Sets 1D texture image data.
- Parameters:
target- Texture targetlevel- Mipmap level (int)internal_format- Internal format (int)width- Image width (int)border- Border width (int)format- Pixel formattype- Pixel data typepixels- Image data (bytes) ornull- Returns:
null
tex_image2d(target, level, internal_format, width, height, border, format, type, pixels)
Sets 2D texture image data.
- Parameters:
target- Texture targetlevel- Mipmap level (int)internal_format- Internal format (int)width,height- Image dimensions (int)border- Border width (int)format- Pixel formattype- Pixel data typepixels- Image data (bytes) ornull- Returns:
null - Example:
go gl.tex_image2d(gl.TEXTURE_2D, 0, gl.RGB, 256, 256, 0, gl.RGB, gl.UNSIGNED_BYTE, image_bytes)
tex_image3d(target, level, internal_format, width, height, depth, border, format, type, pixels)
Sets 3D texture image data.
- Parameters:
target- Texture targetlevel- Mipmap level (int)internal_format- Internal format (int)width,height,depth- Image dimensions (int)border- Border width (int)format- Pixel formattype- Pixel data typepixels- Image data (bytes) ornull- Returns:
null
tex_sub_image1d(target, level, xoffset, width, format, type, pixels)
Specifies a sub-rectangle of the current 1D texture image.
- Returns:
null
tex_sub_image2d(target, level, xoffset, yoffset, width, height, format, type, pixels)
Specifies a sub-rectangle of the current 2D texture image.
- Returns:
null
tex_sub_image3d(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels)
Specifies a sub-rectangle of the current 3D texture image.
- Returns:
null
copy_tex_image2d(target, level, internal_format, x, y, width, height, border)
Copies pixels from the framebuffer to a 2D texture image.
- Parameters:
target- Texture targetlevel- Mipmap level (int)internal_format- Internal format (uint)x,y- Framebuffer coordinates (int)width,height- Image dimensions (int)border- Border width (int)- Returns:
null
copy_tex_sub_image2d(target, level, xoffset, yoffset, x, y, width, height)
Copies pixels from the framebuffer to a sub-rectangle of the current 2D texture.
- Returns:
null
tex_parameterf(target, pname, param)
tex_parameteri(target, pname, param)
tex_parameterfv(target, pname, ...params)
tex_parameteriv(target, pname, ...params)
Sets texture parameters.
- Parameters:
target- Texture target,pname- Parameter name,param(s)- Parameter value(s) - Returns:
null - Example:
go gl.tex_parameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR) gl.tex_parameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) gl.tex_parameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
get_tex_parameteriv(target, pname)
get_tex_parameterfv(target, pname)
Queries texture parameter values.
- Parameters:
target- Texture target,pname- Parameter name - Returns: Parameter value (int or float)
- Example:
min_filter := gl.get_tex_parameteriv(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER)
get_tex_image(target, level, format, type, pixels)
Returns texture image data.
- Parameters:
target- Texture targetlevel- Mipmap level (int)format- Pixel formattype- Pixel data typepixels- Byte slice to receive the data- Returns:
null
tex_envf(target, pname, param)
tex_envi(target, pname, param)
tex_envfv(target, pname, ...params)
tex_enviv(target, pname, ...params)
Sets texture environment parameters.
- Returns:
null
tex_genf(coord, pname, param)
tex_gend(coord, pname, param)
tex_geni(coord, pname, param)
Sets texture coordinate generation parameters.
- Returns:
null
Pixel Operations
bitmap(width, height, xorig, yorig, xmove, ymove, bitmap)
Draws a bitmap (monochrome image).
- Parameters:
width,height- Bitmap dimensions (int)xorig,yorig- Origin of bitmap (float)xmove,ymove- Cursor movement after drawing (float)bitmap- Bitmap data (bytes) ornull- Returns:
null
draw_pixels(width, height, format, type, pixels)
Draws a rectangle of pixel data.
- Parameters:
width,height- Image dimensions (int)format- Pixel formattype- Pixel data typepixels- Pixel data (bytes)- Returns:
null
read_pixels(x, y, width, height, format, type, pixels)
Reads pixels from the framebuffer.
- Parameters:
x,y- Lower-left corner (int)width,height- Rectangle dimensions (int)format- Pixel formattype- Pixel data typepixels- Byte slice to receive the data- Returns:
null - Example:
go pixels := make([]byte, 800*600*4) gl.read_pixels(0, 0, 800, 600, gl.RGBA, gl.UNSIGNED_BYTE, pixels)
copy_pixels(x, y, width, height, type)
Copies a block of pixels within the framebuffer.
- Parameters:
x,y- Source lower-left corner (int)width,height- Rectangle dimensions (int)type-gl.COLOR,gl.DEPTH, orgl.STENCIL- Returns:
null
pixel_zoom(xfactor, yfactor)
Sets pixel zoom factors for draw/copy operations.
- Parameters:
xfactor,yfactor- Zoom factors (float) - Returns:
null
raster_pos2i(x, y)
raster_pos2f(x, y)
raster_pos3f(x, y, z)
Sets the current raster position.
- Parameters: Position coordinates (int or float)
- Returns:
null - Example:
gl.raster_pos2i(100, 200)
color_mask(red, green, blue, alpha)
Enables or disables writing of colour components.
- Parameters: Boolean values for each colour component
- Returns:
null - Example:
gl.color_mask(true, true, true, false)
logic_op(opcode)
Sets the logical operation for pixel writes.
- Parameters:
opcode- Logical operation (gl.CLEAR,gl.AND,gl.OR,gl.XOR, etc.) - Returns:
null
pixel_storei(pname, param)
Sets pixel storage modes.
- Parameters:
pname-gl.PACK_ALIGNMENT,gl.UNPACK_ALIGNMENT, etc.,param- Value (int) - Returns:
null
Clipping Planes
clip_plane(plane, eq0, eq1, eq2, eq3)
Defines a clipping plane.
- Parameters:
plane- Plane number (gl.CLIP_PLANE0throughgl.CLIP_PLANE5)eq0,eq1,eq2,eq3- Plane equation coefficients (float)- Returns:
null - Example:
gl.clip_plane(gl.CLIP_PLANE0, 0, 1, 0, 0)
Vertex Arrays
enable_client_state(array)
disable_client_state(array)
Enables or disables client-side vertex arrays.
- Parameters:
array-gl.VERTEX_ARRAY,gl.NORMAL_ARRAY,gl.COLOR_ARRAY,gl.TEXTURE_COORD_ARRAY - Returns:
null
vertex_pointer(size, type, stride, pointer)
normal_pointer(type, stride, pointer)
color_pointer(size, type, stride, pointer)
tex_coord_pointer(size, type, stride, pointer)
Specifies vertex array pointers.
- Parameters:
pointer- Data (bytes) ornull - Returns:
null - Example:
go gl.enable_client_state(gl.VERTEX_ARRAY) gl.vertex_pointer(3, gl.FLOAT, 0, vertex_data)
draw_arrays(mode, first, count)
Renders primitives from array data.
- Parameters:
mode- Primitive type,first- Starting index (int),count- Number of vertices (int) - Returns:
null
draw_elements(mode, count, type, indices)
Renders primitives from indexed array data.
- Parameters:
indices- Index data (bytes) ornull - Returns:
null
Display Lists
gen_lists(range)
Generates display list names.
- Parameters:
range- Number of display lists to generate (int) - Returns: Starting display list ID (int)
new_list(list, mode)
Begins a display list.
- Parameters:
list- Display list ID (uint),mode-gl.COMPILEorgl.COMPILE_AND_EXECUTE - Returns:
null
end_list()
Ends a display list.
- Returns:
null
call_list(list)
Executes a display list.
- Parameters:
list- Display list ID (uint) - Returns:
null
delete_lists(list, range)
Deletes display lists.
- Parameters:
list- Starting display list ID (uint),range- Number of lists to delete (int) - Returns:
null
Query & Sync
get_error()
Returns the current OpenGL error code.
- Returns: Error code (int)
- Example:
go err := gl.get_error() if err != gl.NO_ERROR { println("OpenGL error:", err) }
get_integerv(pname)
get_floatv(pname)
get_doublev(pname)
get_booleanv(pname)
Queries OpenGL state values.
- Parameters:
pname- Parameter to query - Returns: Query result (int, float, or bool)
get_string(name)
Returns a string from OpenGL.
- Parameters:
name-gl.VENDOR,gl.RENDERER,gl.VERSION, orgl.EXTENSIONS - Returns: String
- Example:
println("OpenGL Version:", gl.get_string(gl.VERSION))
Flush & Finish
flush()
Forces execution of OpenGL commands.
- Returns:
null
finish()
Waits for all OpenGL commands to complete.
- Returns:
null
Accumulation Buffer
accum(op, value)
Performs accumulation buffer operations.
- Parameters:
op-gl.ACCUM,gl.LOAD,gl.RETURN,gl.MULT, orgl.ADD,value- Operation value (float) - Returns:
null
Render Mode
render_mode(mode)
Sets the render mode.
- Parameters:
mode-gl.RENDER,gl.FEEDBACK, orgl.SELECT - Returns: Previous render mode (int)
Constants Reference
Matrix Modes
gl.MODELVIEWgl.PROJECTIONgl.TEXTURE
Clear Bits
gl.COLOR_BUFFER_BITgl.DEPTH_BUFFER_BITgl.ACCUM_BUFFER_BITgl.STENCIL_BUFFER_BIT
Primitive Types
gl.POINTSgl.LINESgl.LINE_LOOPgl.LINE_STRIPgl.TRIANGLESgl.TRIANGLE_STRIPgl.TRIANGLE_FANgl.QUADSgl.QUAD_STRIPgl.POLYGON
Shading Models
gl.FLATgl.SMOOTH
Capabilities
gl.BLENDgl.DEPTH_TESTgl.CULL_FACEgl.LIGHTINGgl.LIGHT0throughgl.LIGHT7gl.FOGgl.SCISSOR_TESTgl.STENCIL_TESTgl.ALPHA_TESTgl.NORMALIZEgl.COLOR_MATERIAL
Blend Factors
gl.ZEROgl.ONEgl.SRC_COLORgl.ONE_MINUS_SRC_COLORgl.DST_COLORgl.ONE_MINUS_DST_COLORgl.SRC_ALPHAgl.ONE_MINUS_SRC_ALPHAgl.DST_ALPHAgl.ONE_MINUS_DST_ALPHAgl.SRC_ALPHA_SATURATEgl.CONSTANT_COLORgl.ONE_MINUS_CONSTANT_COLORgl.CONSTANT_ALPHAgl.ONE_MINUS_CONSTANT_ALPHA
Blend Equations
gl.FUNC_ADDgl.FUNC_SUBTRACTgl.FUNC_REVERSE_SUBTRACTgl.MINgl.MAX
Depth/Alpha Functions
gl.NEVERgl.LESSgl.EQUALgl.LEQUALgl.GREATERgl.NOTEQUALgl.GEQUALgl.ALWAYS
Cull Face Modes
gl.FRONTgl.BACKgl.FRONT_AND_BACK
Front Face
gl.CW(clockwise)gl.CCW(counter-clockwise)
Polygon Modes
gl.POINTgl.LINEgl.FILL
Hints
gl.DONT_CAREgl.FASTESTgl.NICEST
Fog Modes
gl.EXPgl.EXP2
Texture Targets
gl.TEXTURE_1Dgl.TEXTURE_2Dgl.TEXTURE_3Dgl.TEXTURE_CUBE_MAPgl.TEXTURE_CUBE_MAP_POSITIVE_Xthroughgl.TEXTURE_CUBE_MAP_NEGATIVE_Z
Texture Filters
gl.NEARESTgl.LINEARgl.NEAREST_MIPMAP_NEARESTgl.LINEAR_MIPMAP_NEARESTgl.NEAREST_MIPMAP_LINEARgl.LINEAR_MIPMAP_LINEAR
Texture Wrap Modes
gl.CLAMPgl.REPEATgl.CLAMP_TO_EDGEgl.CLAMP_TO_BORDERgl.MIRRORED_REPEAT
Internal Formats
gl.ALPHA,gl.ALPHA4,gl.ALPHA8,gl.ALPHA12,gl.ALPHA16gl.LUMINANCE,gl.LUMINANCE4,gl.LUMINANCE8,gl.LUMINANCE12,gl.LUMINANCE16gl.LUMINANCE_ALPHA,gl.LUMINANCE4_ALPHA4,gl.LUMINANCE8_ALPHA8gl.RGB,gl.RGB4,gl.RGB8,gl.RGB10,gl.RGB12,gl.RGB16gl.RGBA,gl.RGBA2,gl.RGBA4,gl.RGB5_A1,gl.RGBA8,gl.RGB10_A2,gl.RGBA12,gl.RGBA16gl.DEPTH_COMPONENT,gl.DEPTH_COMPONENT16,gl.DEPTH_COMPONENT24,gl.DEPTH_COMPONENT32
Pixel Data Types
gl.UNSIGNED_BYTEgl.BYTEgl.UNSIGNED_SHORTgl.SHORTgl.UNSIGNED_INTgl.INTgl.FLOATgl.DOUBLE
Vertex Arrays
gl.VERTEX_ARRAYgl.NORMAL_ARRAYgl.COLOR_ARRAYgl.TEXTURE_COORD_ARRAY
Error Codes
gl.NO_ERRORgl.INVALID_ENUMgl.INVALID_VALUEgl.INVALID_OPERATIONgl.STACK_OVERFLOWgl.STACK_UNDERFLOWgl.OUT_OF_MEMORY
GetString Names
gl.VENDORgl.RENDERERgl.VERSIONgl.EXTENSIONS
Complete Example
import "gl"
// Initialize OpenGL
gl.init()
// Set up the viewport
gl.viewport(0, 0, 800, 600)
// Set up projection matrix
gl.matrix_mode(gl.PROJECTION)
gl.load_identity()
gl.ortho(-1, 1, -1, 1, -1, 1)
// Set up modelview matrix
gl.matrix_mode(gl.MODELVIEW)
gl.load_identity()
// Clear the screen
gl.clear_color(0.2, 0.3, 0.4, 1.0)
gl.clear(gl.COLOR_BUFFER_BIT)
// Enable features
gl.enable(gl.BLEND)
gl.blend_func(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
// Draw a triangle
gl.begin(gl.TRIANGLES)
gl.color3f(1.0, 0.0, 0.0)
gl.vertex3f(400, 100, 0)
gl.color3f(0.0, 1.0, 0.0)
gl.vertex3f(200, 400, 0)
gl.color3f(0.0, 0.0, 1.0)
gl.vertex3f(600, 400, 0)
gl.end()
// Draw a textured quad
gl.enable(gl.TEXTURE_2D)
textures := gl.gen_textures(1)
gl.bind_texture(gl.TEXTURE_2D, textures[0])
gl.tex_parameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
gl.tex_parameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
// ... set texture data with gl.tex_image2d ...
gl.begin(gl.QUADS)
gl.tex_coord2f(0, 0)
gl.vertex3f(0, 0, 0)
gl.tex_coord2f(1, 0)
gl.vertex3f(100, 0, 0)
gl.tex_coord2f(1, 1)
gl.vertex3f(100, 100, 0)
gl.tex_coord2f(0, 1)
gl.vertex3f(0, 100, 0)
gl.end()
// Flush commands
gl.flush()