#[macro_use]
extern crate glium;
#[cfg(feature = "image")]
extern crate image;
use std::io::Cursor;
#[cfg(not(feature = "image"))]
fn main() { println!("This example requires the `image` feature to be enabled"); }
#[cfg(feature = "image")]
fn main() {
use glium::{DisplayBuild, Surface};
let display = glium::glutin::WindowBuilder::new().build_glium().unwrap();
let image = image::load(Cursor::new(&include_bytes!("../tests/fixture/opengl.png")[..]),
image::PNG).unwrap();
let texture = glium::texture::Texture2d::new(&display, image);
#[derive(Copy, Clone)]
struct Vertex {
position: [f32; 2],
tex_coords: [f32; 2],
}
implement_vertex!(Vertex, position, tex_coords);
let vertex1 = Vertex { position: [-0.5, -0.5], tex_coords: [0.0, 0.0] };
let vertex2 = Vertex { position: [ 0.0, 0.5], tex_coords: [0.0, 1.0] };
let vertex3 = Vertex { position: [ 0.5, -0.25], tex_coords: [1.0, 0.0] };
let shape = vec![vertex1, vertex2, vertex3];
let vertex_buffer = glium::VertexBuffer::new(&display, shape);
let indices = glium::index::NoIndices(glium::index::PrimitiveType::TrianglesList);
let vertex_shader_src = r#"
#version 140
in vec2 position;
in vec2 tex_coords;
out vec2 v_tex_coords;
uniform mat4 matrix;
void main() {
v_tex_coords = tex_coords;
gl_Position = matrix * vec4(position, 0.0, 1.0);
}
"#;
let fragment_shader_src = r#"
#version 140
in vec2 v_tex_coords;
out vec4 color;
uniform sampler2D tex;
void main() {
color = texture(tex, v_tex_coords);
}
"#;
let program = glium::Program::from_source(&display, vertex_shader_src, fragment_shader_src, None).unwrap();
let mut t = -0.5;
loop {
t += 0.0002;
if t > 0.5 {
t = -0.5;
}
let mut target = display.draw();
target.clear_color(0.0, 0.0, 1.0, 1.0);
let uniforms = uniform! {
matrix: [
[1.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
[ t , 0.0, 0.0, 1.0],
],
tex: &texture,
};
target.draw(&vertex_buffer, &indices, &program, &uniforms,
&Default::default()).unwrap();
target.finish().unwrap();
for ev in display.poll_events() {
match ev {
glium::glutin::Event::Closed => return,
_ => ()
}
}
}
}