Teapot Loading
This commit is contained in:
parent
dfbb124ce3
commit
6b9869cd37
Binary file not shown.
Before Width: | Height: | Size: 71 KiB |
9
assets/shaders/teapot/teapot.frag
Normal file
9
assets/shaders/teapot/teapot.frag
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#version 140
|
||||||
|
|
||||||
|
out vec4 color;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
color = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
10
assets/shaders/teapot/teapot.vert
Normal file
10
assets/shaders/teapot/teapot.vert
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#version 140
|
||||||
|
|
||||||
|
in vec3 position;
|
||||||
|
in vec3 normal;
|
||||||
|
|
||||||
|
uniform mat4 matrix;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = matrix * vec4(position, 1.0);
|
||||||
|
}
|
75
src/main.rs
75
src/main.rs
|
@ -1,6 +1,6 @@
|
||||||
#![feature(const_fn_trait_bound)]
|
#![feature(const_fn_trait_bound)]
|
||||||
|
|
||||||
use std::io::Cursor;
|
use std::{collections::HashMap, io::Cursor};
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate glium;
|
extern crate glium;
|
||||||
|
@ -136,27 +136,68 @@ fn main() {
|
||||||
let mut target = display.draw();
|
let mut target = display.draw();
|
||||||
target.clear_color(0.0, 0.0, 1.0, 1.0);
|
target.clear_color(0.0, 0.0, 1.0, 1.0);
|
||||||
|
|
||||||
let uniforms = uniform! {
|
{
|
||||||
matrix: [
|
// draw the triangle
|
||||||
[1.0, 0.0, 0.0, 0.0],
|
let uniforms = uniform! {
|
||||||
[0.0, 1.0, 0.0, 0.0],
|
matrix: [
|
||||||
[0.0, 0.0, 1.0, 0.0],
|
[1.0, 0.0, 0.0, 0.0],
|
||||||
[ t , 0.0, 0.0, 1.0f32],
|
[0.0, 1.0, 0.0, 0.0],
|
||||||
],
|
[0.0, 0.0, 1.0, 0.0],
|
||||||
tex: &texture,
|
[ t , 0.0, 0.0, 1.0f32],
|
||||||
|
],
|
||||||
|
tex: &texture,
|
||||||
|
};
|
||||||
|
|
||||||
|
target
|
||||||
|
.draw(
|
||||||
|
&vertex_buffer,
|
||||||
|
&indices,
|
||||||
|
&program,
|
||||||
|
&uniforms,
|
||||||
|
&Default::default(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// Teapot stage
|
||||||
|
let vertex_shader_src = include_str!("../assets/shaders/teapot/teapot.vert");
|
||||||
|
let fragment_shader_src = include_str!("../assets/shaders/teapot/teapot.frag");
|
||||||
|
|
||||||
};
|
let program =
|
||||||
|
glium::Program::from_source(&display, vertex_shader_src, fragment_shader_src, None)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
target
|
let positions = glium::VertexBuffer::new(&display, &teapot::VERTICES).unwrap();
|
||||||
.draw(
|
let normals = glium::VertexBuffer::new(&display, &teapot::NORMALS).unwrap();
|
||||||
&vertex_buffer,
|
let indices = glium::IndexBuffer::new(
|
||||||
&indices,
|
&display,
|
||||||
&program,
|
glium::index::PrimitiveType::TrianglesList,
|
||||||
&uniforms,
|
&teapot::INDICES,
|
||||||
&Default::default(),
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let matrix = [
|
||||||
|
[0.01, 0.0, 0.0, 0.0],
|
||||||
|
[0.0, 0.01, 0.0, 0.0],
|
||||||
|
[0.0, 0.0, 0.01, 0.0],
|
||||||
|
[0.0, 0.0, 0.0, 1.0f32],
|
||||||
|
];
|
||||||
|
|
||||||
|
target
|
||||||
|
.draw(
|
||||||
|
(&positions, &normals),
|
||||||
|
&indices,
|
||||||
|
&program,
|
||||||
|
&uniform! { matrix: matrix },
|
||||||
|
&Default::default(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
target.finish().unwrap();
|
target.finish().unwrap();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod teapot;
|
||||||
|
|
||||||
|
pub type ShaderList = HashMap<String, glium::Program>;
|
||||||
|
|
2110
src/teapot.rs
Normal file
2110
src/teapot.rs
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue