Skip to content

kvark/gl-rs

This branch is 645 commits behind brendanzab/gl-rs:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

cfc6f0b · Aug 31, 2014
Aug 12, 2014
Aug 31, 2014
Aug 31, 2014
Aug 31, 2014
Aug 6, 2014
Aug 12, 2014
Aug 13, 2014
Oct 2, 2013
Aug 20, 2014
Sep 27, 2013
Aug 12, 2014

Repository files navigation

gl-rs

An OpenGL function pointer loader for the Rust Programming Language.

Installation

To use the library, add this to your Cargo.toml:

[dependencies.gl]
git = "https://github.com/bjz/gl-rs"

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 can 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/bjz/glfw-rs):

// the supplied function must be of the type:
// `&fn(symbol: &str) -> Option<extern "C" fn()>`
gl::load_with(|s| glfw.get_proc_address(s));

// loading a specific function pointer
gl::Viewport::load_with(|s| glfw.get_proc_address(s));

Calling a function that has not been loaded will result in a failure like: fail!("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...
}

About

An OpenGL function pointer loader for Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%