Code Monkey home page Code Monkey logo

gl-rs's Introduction

gl-rs

An OpenGL function pointer loader for the Rust Programming Language.

Compilation

rustpkg build --opt-level=3 gl

Usage

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

extern mod 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(glfw::get_proc_address);

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

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

Generating the loader

The loader in gl.rs is generated using the [XML API Registry] (http://www.opengl.org/discussion_boards/showthread.php/181927-New-XML-based-API-Registry-released?p=1251775). If you would like to generate the loader yourself, please refer to the README in the src/generator directory.

Todo

  • Make the generator work properly GLX and WGL.

gl-rs's People

Contributors

brendanzab avatar emberian avatar zeux avatar serge-rgb avatar zokier avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.