| 1 |
mod pan {
|
| 2 |
extern crate panem_nostrum_quotidianum;
|
| 3 |
pub use self::panem_nostrum_quotidianum::*;
|
| 4 |
}
|
| 5 |
mod gl {
|
| 6 |
extern crate gl;
|
| 7 |
pub use self::gl::types::*;
|
| 8 |
pub use self::gl::*;
|
| 9 |
}
|
| 10 |
extern crate glutin;
|
| 11 |
use std::ptr;
|
| 12 |
|
| 13 |
static VERTEX_DATA: [gl::GLfloat; 6] = [0.0, 0.5, 0.5, -0.5, -0.5, -0.5];
|
| 14 |
|
| 15 |
|
| 16 |
// Shader sources
|
| 17 |
static VS_SRC: &'static str = "
|
| 18 |
#version 150
|
| 19 |
in vec3 position;
|
| 20 |
void main() {
|
| 21 |
gl_Position = vec4(position, 1.0);
|
| 22 |
}";
|
| 23 |
|
| 24 |
static FS_SRC: &'static str = "
|
| 25 |
#version 150
|
| 26 |
out vec4 out_color;
|
| 27 |
void main() {
|
| 28 |
out_color = vec4(1.0, 1.0, 1.0, 1.0);
|
| 29 |
}";
|
| 30 |
|
| 31 |
pub fn main_loop() -> Result<(), pan::Error> {
|
| 32 |
let window = pan::Window::create()?;
|
| 33 |
|
| 34 |
let vs = pan::Shader::compile(pan::ShaderType::Vertex, VS_SRC)?;
|
| 35 |
let fs = pan::Shader::compile(pan::ShaderType::Fragment, FS_SRC)?;
|
| 36 |
let program = pan::Program::link(vec![vs, fs])?;
|
| 37 |
|
| 38 |
let vbo = pan::VertexBuffer::new_array_buffer(
|
| 39 |
pan::VertexArray::new(),
|
| 40 |
&VERTEX_DATA,
|
| 41 |
);
|
| 42 |
|
| 43 |
program.use_program();
|
| 44 |
program.bind_frag_data_location(0, "out_color")?;
|
| 45 |
let pos_attr = program.get_attrib_location("position")?;
|
| 46 |
|
| 47 |
unsafe {
|
| 48 |
gl::EnableVertexAttribArray(pos_attr as gl::GLuint);
|
| 49 |
gl::VertexAttribPointer(
|
| 50 |
pos_attr as gl::GLuint,
|
| 51 |
3,
|
| 52 |
gl::FLOAT,
|
| 53 |
gl::FALSE as gl::GLboolean,
|
| 54 |
0,
|
| 55 |
ptr::null(),
|
| 56 |
);
|
| 57 |
}
|
| 58 |
|
| 59 |
vbo.unbind();
|
| 60 |
|
| 61 |
window.run(|event| {
|
| 62 |
use glutin::{ControlFlow, Event, WindowEvent, VirtualKeyCode};
|
| 63 |
|
| 64 |
println!("{:?}", event);
|
| 65 |
match event {
|
| 66 |
Event::WindowEvent { event: WindowEvent::Closed, .. } =>
|
| 67 |
return ControlFlow::Break,
|
| 68 |
Event::WindowEvent {
|
| 69 |
event: WindowEvent::KeyboardInput {
|
| 70 |
input: k,
|
| 71 |
..
|
| 72 |
},
|
| 73 |
..
|
| 74 |
} => {
|
| 75 |
match k.virtual_keycode {
|
| 76 |
Some(VirtualKeyCode::Q) =>
|
| 77 |
return ControlFlow::Break,
|
| 78 |
_ => println!("{:#?}", k),
|
| 79 |
}
|
| 80 |
}
|
| 81 |
_ => (),
|
| 82 |
}
|
| 83 |
|
| 84 |
unsafe {
|
| 85 |
gl::ClearColor(0.3, 0.3, 0.3, 1.0);
|
| 86 |
gl::Clear(gl::COLOR_BUFFER_BIT);
|
| 87 |
|
| 88 |
vbo.bind();
|
| 89 |
|
| 90 |
gl::DrawArrays(gl::TRIANGLES, 0, 3);
|
| 91 |
}
|
| 92 |
|
| 93 |
ControlFlow::Continue
|
| 94 |
})?;
|
| 95 |
|
| 96 |
Ok(())
|
| 97 |
}
|
| 98 |
|
| 99 |
|
| 100 |
fn main() {
|
| 101 |
if let Err(err) = main_loop() {
|
| 102 |
println!("{:?}", err);
|
| 103 |
}
|
| 104 |
}
|