Skip to content

Commit

Permalink
Fix shader handling; small readme updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bwasty committed Jul 15, 2017
1 parent bfaac31 commit c423bb6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# gltf-viewer
[![crates.io](https://img.shields.io/crates/v/gltf-viewer.svg)](https://crates.io/crates/gltf-viewer)
[![](https://tokei.rs/b1/github/bwasty/gltf-viewer)](https://github.com/Aaronepower/tokei)
[![](https://tokei.rs/b1/github/bwasty/gltf-viewer?category=comments)](https://github.com/Aaronepower/tokei) [![Build Status](https://travis-ci.org/bwasty/gltf-viewer.svg?branch=master)](https://travis-ci.org/bwasty/gltf-viewer)
[![Build Status](https://travis-ci.org/bwasty/gltf-viewer.svg?branch=master)](https://travis-ci.org/bwasty/gltf-viewer)

glTF Viewer written in Rust (WIP).
Current state: most simple models can be loaded, but there is no lighting/texturing (normals are used as color):
Expand All @@ -13,7 +13,7 @@ Current state: most simple models can be loaded, but there is no lighting/textur
```shell
cargo install gltf-viewer
```
### Manual
### From source
```shell
git clone https://github.com/bwasty/gltf-viewer.git
cd gltf-viewer
Expand All @@ -27,7 +27,7 @@ gltf-viewer <filename|URL>
Both .gltf and .glb files are supported.
Navigate the scene with `WASD` + Mouse.

Example:
### Example
```
gltf-viewer https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/BarramundiFish/glTF/BarramundiFish.gltf
```
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ pub fn main() {
let (shader, scene) = unsafe {
gl::Enable(gl::DEPTH_TEST);

let shader = Shader::new("src/shaders/simple.vs", "src/shaders/simple.fs");
let shader = Shader::from_source(
include_str!("shaders/simple.vs"),
include_str!("shaders/simple.fs"));

let start = SystemTime::now();
let gltf =
Expand Down
7 changes: 6 additions & 1 deletion src/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub struct Shader {
#[allow(dead_code)]
impl Shader {
pub fn new(vertex_path: &str, fragment_path: &str) -> Shader {
let mut shader = Shader { id: 0 };
// 1. retrieve the vertex/fragment source code from filesystem
let mut v_shader_file = File::open(vertex_path).expect(&format!("Failed to open {}", vertex_path));
let mut f_shader_file = File::open(fragment_path).expect(&format!("Failed to open {}", fragment_path));
Expand All @@ -32,6 +31,12 @@ impl Shader {
.read_to_string(&mut fragment_code)
.expect("Failed to read fragment shader");

Self::from_source(&vertex_code, &fragment_code)
}

pub fn from_source(vertex_code: &str, fragment_code: &str) -> Shader {
let mut shader = Shader { id: 0 };

let v_shader_code = CString::new(vertex_code.as_bytes()).unwrap();
let f_shader_code = CString::new(fragment_code.as_bytes()).unwrap();

Expand Down

0 comments on commit c423bb6

Please sign in to comment.