30 releases

Uses old Rust 2015

0.14.0 Oct 3, 2019
0.13.0 Jul 9, 2019
0.12.0 Apr 1, 2019
0.11.0 Nov 4, 2018
0.0.1 Nov 12, 2014

#28 in Graphics APIs

Download history 5513/week @ 2023-11-23 3892/week @ 2023-11-30 6442/week @ 2023-12-07 8096/week @ 2023-12-14 5069/week @ 2023-12-21 4025/week @ 2023-12-28 4859/week @ 2024-01-04 6054/week @ 2024-01-11 6054/week @ 2024-01-18 5161/week @ 2024-01-25 4957/week @ 2024-02-01 9094/week @ 2024-02-08 8093/week @ 2024-02-15 6947/week @ 2024-02-22 7830/week @ 2024-02-29 5745/week @ 2024-03-07

30,066 downloads per month
Used in 310 crates (150 directly)

Apache-2.0

24KB
282 lines

gl-rs

Version License Downloads

An OpenGL function pointer loader for the Rust Programming Language.

[dependencies]
gl = "0.6.0"

Basic usage

You can import the pointer style loader and type aliases like so:

extern crate gl;
// include the OpenGL type aliases
use gl::types::*;

You must load the function pointers into their respective function pointers using the load_with function. You must supply a loader function from your context library, This is how it would look using [glfw-rs] (https://github.com/PistonDevelopers/glfw-rs):

// the supplied function must be of the type:
// `&fn(symbol: &'static str) -> *const std::os::raw::c_void`
// `window` is a glfw::Window
gl::load_with(|s| window.get_proc_address(s) as *const _);

// loading a specific function pointer
gl::Viewport::load_with(|s| window.get_proc_address(s) as *const _);

Calling a function that has not been loaded will result in a failure like: panic!("gl::Viewport was not loaded"), which avoids a segfault. This feature does not cause any run time overhead because the failing functions are assigned only when load_with is called.

// accessing an enum
gl::RED_BITS;

// calling a function
gl::DrawArrays(gl::TRIANGLES, 0, 3);

// functions that take pointers are unsafe
unsafe {  gl::ShaderSource(shader, 1, &c_str, std::ptr::null()) };

Each function pointer has an associated boolean value allowing you to check if a function has been loaded at run time. The function accesses a corresponding global boolean that is set when load_with is called, so there shouldn't be much overhead.

if gl::Viewport::is_loaded() {
    // do something...
}

Changelog

v0.6.0

  • Upgrade to gl_generator v0.5.0

v0.5.2

  • Update crate metadata

v0.5.1

  • Upgrade khronos_api to v1.0.0

v0.5.0

  • Use glutin for examples
  • Use raw::c_void for GLvoid

No runtime deps

~94KB