6 releases (3 breaking)

0.4.0 Nov 15, 2021
0.3.1 Nov 8, 2021
0.2.1 Nov 8, 2021
0.1.0 Oct 25, 2021

#1079 in Graphics APIs

Zlib OR Apache-2.0 OR MIT

155KB
2.5K SLoC

glitz


lib.rs:

The GL docs here are adapted from the official Khronos GL documentation (license).

This is a crate for using "raw" GL calls, with all GL functions stored in a [GlFns] struct.

The struct has one method per function pointer. Every method just calls the appropriate function pointer held inside. The method names match the usual GL function names with the "gl" prefix removed. It's expected that you'll bind the struct itself to a variable named gl, and then call a function such as glClear with gl.Clear.

All of the pointers in GlFns are non-nullable function pointers. This skips the program needing to do a null check on every single GL function call. The downside is that if any expected function pointer fails to load, the entire loading process will fail.

The current list of functions supported by this crate is much less than all possible GL functions. Right now the crate assumes OpenGL 3.3 + GL_KHR_debug is available. This configuration is widely supported on Windows, Mac, and Linux. Even then, the exact list of functions that are loaded is only a subset of the full possibilities.

In the future, the crate might offer a way to more precisely configure at compile time which functions are included or not.

Example Usage

use glitz::*;

unimplemented!("set up the GL context and be ready to load functions");

let loader_fn = |c_str: *const u8| {
  // The loader fn is intended to accept a null-termianted-pointer.
  // This matches up with SDL_GL_GetProcAddress, wglGetProcAddress,
  // GetProcAddress, and similar.
  unimplemented!("use the OS or a lib to load a fn by name.");

  // If you're using a rust lib that expects `&str` values, you can
  // convert the pointer like this:
  let _s: &str =
    unsafe { std::ffi::CStr::from_ptr(c_str.cast()).to_str().unwrap() };
};

let gl = unsafe { GlFns::from_loader(&loader_fn).unwrap() };

gl.ClearColor(0.5, 0.5, 0.5, 1.0);
gl.Clear(GL_COLOR_BUFFER_BIT);

Dependencies

~40KB