• Home
Name Date Size #Lines LOC

..--

examples/04-Jul-2025-250164

out/04-Jul-2025-21,33918,144

patches/04-Jul-2025-208207

src/04-Jul-2025-803

.android-checksum.jsonD04-Jul-20251.3 KiB11

.cargo-checksum.jsonD04-Jul-2025662 11

Android.bpD04-Jul-2025976 4035

Cargo.lockD04-Jul-202536 KiB793707

Cargo.tomlD04-Jul-20251.1 KiB3028

LICENSED04-Jul-202511.1 KiB201169

METADATAD04-Jul-2025334 1817

MODULE_LICENSE_APACHE2D04-Jul-20250

README.mdD04-Jul-20252.1 KiB8459

build.rsD04-Jul-20251 KiB3012

cargo_embargo.jsonD04-Jul-202590 88

README.md

1# gl-rs
2
3[![Version](https://img.shields.io/crates/v/gl.svg)](https://crates.io/crates/gl)
4[![License](https://img.shields.io/crates/l/gl.svg)](https://github.com/brendanzab/gl-rs/blob/master/LICENSE)
5[![Downloads](https://img.shields.io/crates/d/gl.svg)](https://crates.io/crates/gl)
6
7An OpenGL function pointer loader for the Rust Programming Language.
8
9```toml
10[dependencies]
11gl = "0.6.0"
12```
13
14## Basic usage
15
16You can import the pointer style loader and type aliases like so:
17
18```rust
19extern crate gl;
20// include the OpenGL type aliases
21use gl::types::*;
22```
23
24You must load the function pointers into their respective function pointers
25using the `load_with` function. You must supply a loader function from your
26context library, This is how it would look using [glfw-rs]
27(https://github.com/PistonDevelopers/glfw-rs):
28
29```rust
30// the supplied function must be of the type:
31// `&fn(symbol: &'static str) -> *const std::os::raw::c_void`
32// `window` is a glfw::Window
33gl::load_with(|s| window.get_proc_address(s) as *const _);
34
35// loading a specific function pointer
36gl::Viewport::load_with(|s| window.get_proc_address(s) as *const _);
37```
38
39Calling a function that has not been loaded will result in a failure like:
40`panic!("gl::Viewport was not loaded")`, which avoids a segfault. This feature
41does not cause any run time overhead because the failing functions are
42assigned only when `load_with` is called.
43
44```rust
45// accessing an enum
46gl::RED_BITS;
47
48// calling a function
49gl::DrawArrays(gl::TRIANGLES, 0, 3);
50
51// functions that take pointers are unsafe
52unsafe {  gl::ShaderSource(shader, 1, &c_str, std::ptr::null()) };
53```
54
55Each function pointer has an associated boolean value allowing you to
56check if a function has been loaded at run time. The function accesses a
57corresponding global boolean that is set when `load_with` is called, so there
58shouldn't be much overhead.
59
60```rust
61if gl::Viewport::is_loaded() {
62    // do something...
63}
64```
65
66## Changelog
67
68### v0.6.0
69
70- Upgrade to `gl_generator` v0.5.0
71
72### v0.5.2
73
74- Update crate metadata
75
76### v0.5.1
77
78- Upgrade `khronos_api` to v1.0.0
79
80### v0.5.0
81
82- Use `glutin` for examples
83- Use `raw::c_void` for `GLvoid`
84