Skip to content

opengl

stable

Low-level OpenGL 3.3 Core wrapper via the glow crate, providing context creation, shader compilation, buffer and texture management, and draw calls on Windows.

use plugin opengl::{create_context, make_current, swap_buffers, …}
49 functions Graphics
/ filter jk navigate Esc clear
Functions (49)
  1. create_context Create an OpenGL context for a window handle
  2. make_current Make the GL context current (no-op with CS_OWNDC)
  3. swap_buffers Present the back buffer to the screen
  4. viewport Set the GL viewport rectangle
  5. clear_color Set the clear color (RGBA floats 0–1)
  6. clear Clear one or more framebuffer attachments
  7. enable Enable a GL capability by name
  8. disable Disable a GL capability by name
  9. blend_func Set source and destination blend factors
  10. depth_func Set the depth comparison function
  11. scissor Set the scissor rectangle
  12. line_width Set the rasterized line width
  13. color_mask Control per-channel color write masks
  14. depth_mask Enable or disable depth buffer writes
  15. polygon_offset Set polygon offset factor and units
  16. create_shader Compile a GLSL shader from source
  17. create_program Link compiled shaders into a program
  18. use_program Activate a shader program
  19. uniform_location Look up a uniform variable location
  20. set_uniform_1f Set a float uniform
  21. set_uniform_2f Set a vec2 uniform
  22. set_uniform_3f Set a vec3 uniform
  23. set_uniform_4f Set a vec4 uniform
  24. set_uniform_1i Set an integer uniform
  25. set_uniform_mat4 Set a mat4 uniform from 64 bytes
  26. create_buffer Allocate a GL buffer object
  27. buffer_bind Bind a buffer to a target
  28. buffer_data Upload raw bytes to a bound buffer
  29. buffer_data_floats Upload a float table to a bound buffer
  30. create_vertex_array Create a vertex array object (VAO)
  31. vao_bind Bind a VAO
  32. vao_unbind Unbind the current VAO
  33. vao_attrib_pointer Define a vertex attribute layout
  34. vao_enable_attrib Enable a vertex attribute index
  35. delete_shader Delete a shader object
  36. delete_program Delete a shader program
  37. delete_buffer Delete a buffer object
  38. delete_vertex_array Delete a VAO
  39. delete_texture Delete a texture object
  40. create_texture Allocate a GL texture object
  41. texture_bind Bind a texture to a texture unit
  42. texture_image_2d Upload 2D image data to a texture
  43. texture_parameter Set a texture sampling parameter
  44. texture_generate_mipmaps Generate mipmaps for a texture
  45. draw_arrays Draw primitives from vertex arrays
  46. draw_elements Draw primitives using an index buffer
  47. get_error Query the current GL error state
  48. flush Flush queued GL commands
  49. finish Block until all GL commands complete

Create an OpenGL context for a window handle

Creates an OpenGL 3.3 Core context attached to a Win32 window handle (HWND). Accepts either a raw integer HWND or the table returned by win.native_handle(). Returns a GlState handle used by all other functions. Windows only; non-Windows returns an error.

use plugin opengl::{create_context}

let gl = create_context(hwnd)

Make the GL context current (no-op with CS_OWNDC)

Marks the context as current on the calling thread. With CS_OWNDC the context stays current from creation, so this is effectively a no-op but is provided for API completeness.

use plugin opengl::{make_current}

make_current()

Present the back buffer to the screen

Presents the back buffer to the screen by calling SwapBuffers on the device context. Call once per frame after all draw calls.

use plugin opengl::{swap_buffers}

swap_buffers()

Set the GL viewport rectangle

Sets the GL viewport rectangle. Call after create_context and whenever the window is resized.

use plugin opengl::{create_context, viewport}

let gl = create_context(hwnd)
viewport(gl, 0, 0, 800, 600)

Set the clear color (RGBA floats 0–1)

Sets the color used by clear for the color buffer. Values are floats in the range [0, 1].

use plugin opengl::{clear_color, clear}

clear_color(gl, 0.1, 0.1, 0.15, 1.0)
clear(gl, "color+depth")

Clear one or more framebuffer attachments

Clears framebuffer attachments. mask is one of "color", "depth", "stencil", "color+depth", "color+stencil", "depth+stencil", or "all".

use plugin opengl::{clear}

clear(gl, "color+depth")

Enable a GL capability by name

Enables a named GL capability. Supported names: "blend", "depth_test", "cull_face", "scissor_test", "stencil_test", "multisample", "polygon_offset_fill".

use plugin opengl::{enable}

enable(gl, "depth_test")
enable(gl, "blend")

Disable a GL capability by name

Disables a named GL capability.

use plugin opengl::{disable}

disable(gl, "cull_face")

Set source and destination blend factors

Sets the blend equation source and destination factors. Factor names include "src_alpha", "one_minus_src_alpha", "one", "zero", and others.

use plugin opengl::{enable, blend_func}

enable(gl, "blend")
blend_func(gl, "src_alpha", "one_minus_src_alpha")

Set the depth comparison function

Sets the depth comparison function. Values: "less", "lequal", "greater", "gequal", "equal", "notequal", "always", "never".

use plugin opengl::{depth_func}

depth_func(gl, "lequal")

Set the scissor rectangle

Sets the scissor test rectangle. Fragments outside this rectangle are discarded when scissor_test is enabled.

use plugin opengl::{enable, scissor}

enable(gl, "scissor_test")
scissor(gl, 100, 100, 400, 300)

Set the rasterized line width

Sets the width of rasterized lines in pixels.

use plugin opengl::{line_width}

line_width(gl, 2.0)

Control per-channel color write masks

Controls which color channels are written to the framebuffer. Pass true to enable writing, false to mask out a channel.

use plugin opengl::{color_mask}

color_mask(gl, true, true, true, false)

Enable or disable depth buffer writes

Enables (true) or disables (false) writes to the depth buffer.

use plugin opengl::{depth_mask}

depth_mask(gl, false)

Set polygon offset factor and units

Sets the polygon offset scale and bias for polygon_offset_fill. Used to prevent z-fighting when rendering decals over geometry.

use plugin opengl::{enable, polygon_offset}

enable(gl, "polygon_offset_fill")
polygon_offset(gl, 1.0, 1.0)

Compile a GLSL shader from source

Compiles a GLSL shader from source. type is "vertex", "fragment", "geometry", or "compute". Returns a shader handle on success; raises an error with the compile log on failure.

use plugin opengl::{create_shader}

let vert = create_shader(gl, "vertex", "
  #version 330 core
  layout(location=0) in vec3 pos;
  void main() { gl_Position = vec4(pos, 1.0); }
")

Link compiled shaders into a program

Links a table of shader handles into a shader program. Returns a program handle on success; raises an error with the link log on failure. Detaches shaders after linking.

use plugin opengl::{create_shader, create_program, use_program}

let vert = create_shader(gl, "vertex", vert_src)
let frag = create_shader(gl, "fragment", frag_src)
let prog = create_program(gl, #{1: vert, 2: frag})
use_program(prog)

Activate a shader program

Activates a linked shader program for subsequent draw calls.

use plugin opengl::{use_program}

use_program(prog)

Look up a uniform variable location

Looks up a named uniform variable in a linked program. Returns a uniform location handle, or -1 if the name is not found (inactive/optimized-out uniforms).

use plugin opengl::{uniform_location, set_uniform_1f}

let loc = uniform_location(prog, "uTime")
set_uniform_1f(prog, loc, 1.5)

Set a float uniform

Sets a float uniform variable. Requires use_program to have been called with the same program.

use plugin opengl::{set_uniform_1f}

set_uniform_1f(prog, time_loc, 3.14)

Set a vec2 uniform

Sets a vec2 uniform variable.

use plugin opengl::{set_uniform_2f}

set_uniform_2f(prog, res_loc, 800.0, 600.0)

Set a vec3 uniform

Sets a vec3 uniform variable, typically used for colors or world-space positions.

use plugin opengl::{set_uniform_3f}

set_uniform_3f(prog, color_loc, 1.0, 0.5, 0.0)

Set a vec4 uniform

Sets a vec4 uniform variable.

use plugin opengl::{set_uniform_4f}

set_uniform_4f(prog, clear_loc, 0.1, 0.1, 0.15, 1.0)

Set an integer uniform

Sets an int or sampler2D uniform. Use for passing texture unit indices to samplers.

use plugin opengl::{set_uniform_1i}

set_uniform_1i(prog, tex_loc, 0)

Set a mat4 uniform from 64 bytes

Sets a mat4 uniform from exactly 64 bytes of little-endian float data (16 × f32).

use plugin opengl::{set_uniform_mat4}

set_uniform_mat4(prog, mvp_loc, matrix_bytes)

Allocate a GL buffer object

Allocates a new OpenGL buffer object. Use with buffer_bind and buffer_data or buffer_data_floats to upload vertex or index data.

use plugin opengl::{create_buffer, buffer_bind, buffer_data_floats}

let vbo = create_buffer(gl)
buffer_bind(vbo, "array")
buffer_data_floats(vbo, "array", #{1: 0.0, 2: 0.5, 3: 0.0}, "static_draw")

Bind a buffer to a target

Binds a buffer object to the named target. Targets: "array" (vertex data), "element" / "element_array" (index data), "uniform".

use plugin opengl::{buffer_bind}

buffer_bind(vbo, "array")

Upload raw bytes to a bound buffer

Uploads raw bytes to a buffer. usage is "static_draw", "dynamic_draw", or "stream_draw". Also binds the buffer before uploading.

use plugin opengl::{buffer_data}

buffer_data(ibo, "element", index_bytes, "static_draw")

Upload a float table to a bound buffer

Uploads a table of float values to a buffer, converting each to little-endian f32 bytes internally. More convenient than buffer_data when data originates as Zolo numbers.

use plugin opengl::{buffer_data_floats}

let verts = #{1: -0.5, 2: -0.5, 3: 0.0, 4: 0.5, 5: -0.5, 6: 0.0, 7: 0.0, 8: 0.5, 9: 0.0}
buffer_data_floats(vbo, "array", verts, "static_draw")

Create a vertex array object (VAO)

Creates a new vertex array object (VAO) that records vao_attrib_pointer and vao_enable_attrib calls. Bind before configuring attributes.

use plugin opengl::{create_vertex_array, vao_bind}

let vao = create_vertex_array(gl)
vao_bind(vao)

Bind a VAO

Binds a vertex array object, making it the active VAO for subsequent attribute configuration and draw calls.

use plugin opengl::{vao_bind}

vao_bind(vao)

Unbind the current VAO

Unbinds the current VAO (binds 0). Call after finishing attribute setup.

use plugin opengl::{vao_unbind}

vao_unbind(vao)

Define a vertex attribute layout

Defines how a vertex attribute is read from the currently bound array buffer. type is "float", "int", etc. normalized is a bool.

use plugin opengl::{vao_attrib_pointer, vao_enable_attrib}

vao_attrib_pointer(vao, 0, 3, "float", false, 12, 0)
vao_enable_attrib(vao, 0)

Enable a vertex attribute index

Enables vertex attribute array access at the given index for the bound VAO.

use plugin opengl::{vao_enable_attrib}

vao_enable_attrib(vao, 0)

Delete a shader object

Deletes a compiled shader object and frees GPU resources.

use plugin opengl::{delete_shader}

delete_shader(vert_shader)
delete_shader(frag_shader)

Delete a shader program

Deletes a linked shader program.

use plugin opengl::{delete_program}

delete_program(prog)

Delete a buffer object

Deletes a buffer object and frees GPU memory.

use plugin opengl::{delete_buffer}

delete_buffer(vbo)

Delete a VAO

Deletes a vertex array object.

use plugin opengl::{delete_vertex_array}

delete_vertex_array(vao)

Delete a texture object

Deletes a texture object and frees GPU memory.

use plugin opengl::{delete_texture}

delete_texture(tex)

Allocate a GL texture object

Allocates a new 2D texture object. Use with texture_bind, texture_image_2d, and texture_parameter to upload and configure it.

use plugin opengl::{create_texture, texture_bind, texture_image_2d}

let tex = create_texture(gl)
texture_bind(tex, 0)
texture_image_2d(tex, 0, "rgba8", 256, 256, rgba_bytes)

Bind a texture to a texture unit

Activates texture unit unit and binds the texture to GL_TEXTURE_2D.

use plugin opengl::{texture_bind}

texture_bind(tex, 0)

Upload 2D image data to a texture

Uploads 2D image data to a texture. internal_format is "rgba", "rgb", "rgba8", "rgb8", or "red". Input bytes are interpreted as GL_RGBA / GL_UNSIGNED_BYTE.

use plugin opengl::{texture_image_2d}

texture_image_2d(tex, 0, "rgba8", 512, 512, image_bytes)

Set a texture sampling parameter

Sets a texture sampling parameter. name is "min_filter", "mag_filter", "wrap_s", or "wrap_t". value is "linear", "nearest", "clamp_to_edge", "repeat", etc.

use plugin opengl::{texture_parameter}

texture_parameter(tex, "min_filter", "linear")
texture_parameter(tex, "wrap_s", "clamp_to_edge")

Generate mipmaps for a texture

Generates a full mipmap chain for the texture from the base level image. Call after texture_image_2d when using mipmap filter modes.

use plugin opengl::{texture_generate_mipmaps, texture_parameter}

texture_generate_mipmaps(tex)
texture_parameter(tex, "min_filter", "linear_mipmap_linear")

Draw primitives from vertex arrays

Draws count primitives starting at vertex first. mode is "triangles", "triangle_strip", "lines", "points", etc.

use plugin opengl::{draw_arrays}

draw_arrays(gl, "triangles", 0, 3)

Draw primitives using an index buffer

Draws count primitives using indices from the currently bound element array buffer. index_type is "unsigned_short" or "unsigned_int".

use plugin opengl::{draw_elements}

draw_elements(gl, "triangles", 36, "unsigned_short", 0)

Query the current GL error state

Returns the current GL error state as a string: "no_error", "invalid_enum", "invalid_value", "invalid_operation", "out_of_memory", or "unknown_error". Clears the error flag.

use plugin opengl::{get_error}

let err = get_error(gl)
if err != "no_error" {
  print("GL error: {err}")
}

Flush queued GL commands

Flushes all pending GL commands to the GPU command queue without blocking. Use when synchronization is needed without a full stall.

use plugin opengl::{flush}

flush(gl)

Block until all GL commands complete

Blocks until all previously issued GL commands have completed on the GPU. Use for timing measurements or when reading back GPU data.

use plugin opengl::{finish}

finish(gl)
enespt-br