Coder Social home page Coder Social logo

glassful's Introduction

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));
}

glassful's People

Contributors

burtonageo avatar gsingh93 avatar kmcallister avatar ticki avatar

Watchers

 avatar  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.