Display two textured triangles in 3D
This commit is contained in:
+17
-2
@@ -1,6 +1,8 @@
|
||||
#[macro_use]
|
||||
extern crate glium;
|
||||
|
||||
use std::io::Cursor;
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use glium::{glutin, Surface};
|
||||
|
||||
@@ -16,6 +18,12 @@ fn main() {
|
||||
// building the vertex and index buffers
|
||||
let vertex_buffer = support::load_ground(&display);
|
||||
|
||||
let image = image::load(Cursor::new(&include_bytes!("../opengl.png")),
|
||||
image::ImageFormat::Png).unwrap().to_rgba8();
|
||||
let image_dimensions = image.dimensions();
|
||||
let image = glium::texture::RawImage2d::from_raw_rgba_reversed(&image.into_raw(), image_dimensions);
|
||||
let texture = glium::texture::SrgbTexture2d::new(&display, image).unwrap();
|
||||
|
||||
// the program
|
||||
let program = program!(&display,
|
||||
140 => {
|
||||
@@ -27,12 +35,16 @@ fn main() {
|
||||
|
||||
in vec3 position;
|
||||
in vec3 normal;
|
||||
in vec2 tex_coords;
|
||||
|
||||
out vec3 v_position;
|
||||
out vec3 v_normal;
|
||||
out vec2 v_tex_coords;
|
||||
|
||||
void main() {
|
||||
v_position = position;
|
||||
v_normal = normal;
|
||||
v_tex_coords = tex_coords;
|
||||
gl_Position = persp_matrix * view_matrix * vec4(v_position * 0.005, 1.0);
|
||||
}
|
||||
",
|
||||
@@ -41,14 +53,16 @@ fn main() {
|
||||
#version 140
|
||||
|
||||
in vec3 v_normal;
|
||||
in vec2 v_tex_coords;
|
||||
out vec4 f_color;
|
||||
|
||||
uniform sampler2D tex;
|
||||
|
||||
const vec3 LIGHT = vec3(0.0, -1.0, 0.0);
|
||||
|
||||
void main() {
|
||||
float lum = max(dot(normalize(v_normal), normalize(LIGHT)), 0.0);
|
||||
vec3 color = (0.3 + 0.7 * lum) * vec3(1.0, 1.0, 1.0);
|
||||
f_color = vec4(color, 1.0);
|
||||
f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex, v_tex_coords);
|
||||
}
|
||||
"
|
||||
},
|
||||
@@ -65,6 +79,7 @@ fn main() {
|
||||
let uniforms = uniform! {
|
||||
persp_matrix: camera.get_perspective(),
|
||||
view_matrix: camera.get_view(),
|
||||
tex: &texture,
|
||||
};
|
||||
|
||||
// draw parameters
|
||||
|
||||
Reference in New Issue
Block a user