Skip to content
Rust-like syntax for OpenGL Shading Language
Rust
Branch: master
Clone or download
kmcallister Merge pull request #24 from ticki/master
Fix code to match the recent changes to the unstable plugin API, fix example
Latest commit 99db166 Jul 1, 2016
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples/gradient Fix example, to match the latest nightly Jan 24, 2016
macros Fix the macros crate Jan 24, 2016
src Fix code to match the recent changes to the unstable plugin API, add … Jan 24, 2016
tests Remove unused feature(core) to get tests passing Mar 2, 2015
.gitignore
.travis.yml Update travis to use the nightly Jun 27, 2015
Cargo.toml Fix code to match the recent changes to the unstable plugin API, add … Jan 24, 2016
LICENSE-APACHE Document Feb 1, 2015
LICENSE-MIT Document Feb 1, 2015
README.md Updated README Jun 27, 2015

README.md

Rust-like syntax for GLSL

Build Status

glassful translates a small subset of Rust to OpenGL Shading Language.

Besides one's personal preferences regarding Rust-like vs. C-like syntax, this has a few specific advantages for the Rust programmer:

  • Syntax is checked at Rust compile time, with friendly rustc-style errors
  • There's less cognitive overhead switching between CPU and GPU code
  • Shaders can use Rust macros!
  • Shaders embedded in a Rust program have syntax highlighting

The library is still in a very early stage! Many improvements are possible. See the issue tracker and don't hesitate to send pull requests :)

Usage

There are three ways to invoke the translator. The language syntax is exactly the same in all three cases.

As a macro

#![feature(plugin)]

#![plugin(glassful_macros)]

const VERTEX: &'static str = glassful! {
    #![version="110"]

    #[attribute] static position: vec2 = UNINIT;
    #[varying]   static color:    vec3 = UNINIT;

    fn main() {
        gl_Position = vec4(position, 0.0, 1.0);
        color = vec3(0.5*(position + vec2(1.0, 1.0)), 0.0);
    }
};

const FRAGMENT: &'static str = glassful! {
    #![version="110"]

    #[varying] static color: vec3 = UNINIT;

    fn main() {
        gl_FragColor = vec4(color, 1.0);
    }
};

let program = glium::Program::from_source(&display, VERTEX, FRAGMENT, None);

See examples/gradient/ for a full glium/glutin example.

As an external program

$ ./target/glassful < shader.glassful > shader.glsl

As an ordinary library

extern crate glassful;

pub fn main() {
    let prog = io::stdin().read_to_end().unwrap();
    let prog = String::from_utf8(prog).unwrap();
    print!("{}", glassful::translate(prog));
}
You can’t perform that action at this time.