Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[macro_use]
- extern crate gfx;
- extern crate gfx_window_glutin;
- extern crate gfx_device_gl;
- extern crate glutin;
- use gfx::traits::FactoryExt;
- use gfx::Device;
- use gfx_window_glutin as gfx_glutin;
- use glutin::{GlContext, GlRequest};
- use glutin::Api::OpenGl;
- use gfx_device_gl as gfx_gl;
- pub type ColorFormat = gfx::format::Rgba8;
- pub type DepthFormat = gfx::format::DepthStencil;
- const BLACK: [f32; 4] = [0.0, 0.0, 0.0, 1.0];
- gfx_defines!{
- vertex Vertex {
- pos: [f32; 4] = "a_Pos",
- color: [f32; 3] = "a_Color",
- }
- constant Transform {
- transform: [[f32; 4];4] = "u_Transform",
- }
- pipeline pipe {
- vbuf: gfx::VertexBuffer<Vertex> = (),
- transform: gfx::ConstantBuffer<Transform> = "Transform",
- out: gfx::RenderTarget<ColorFormat> = "Target0",
- }
- }
- pub fn main() {
- let mut events_loop = glutin::EventsLoop::new();
- let windowbuilder = glutin::WindowBuilder::new()
- .with_title("Triangle Example".to_string())
- .with_dimensions(512, 512);
- let contextbuilder = glutin::ContextBuilder::new()
- .with_gl(GlRequest::Specific(OpenGl,(3,2)))
- .with_vsync(true);
- let (window, mut device, mut factory, color_view, mut depth_view) =
- gfx_glutin::init::<ColorFormat, DepthFormat>(windowbuilder, contextbuilder, &events_loop);
- let pso = factory.create_pipeline_simple(
- include_bytes!("shaders/simple_vert.glsl"),
- include_bytes!("shaders/simple_frag.glsl"),
- pipe::new()
- ).unwrap();
- let mut command_buffer = factory.create_command_buffer();
- let mut encoder: gfx::Encoder<_, _> = command_buffer.into();
- //let mut c_buffer: () =
- const TRIANGLE: [Vertex; 3] = [
- Vertex { pos: [ -0.5, -0.5, 0.0, 1.0 ], color: [1.0, 0.0, 0.0] },
- Vertex { pos: [ 0.5, -0.5, 0.0, 1.0 ], color: [0.0, 1.0, 0.0] },
- Vertex { pos: [ 0.0, 0.5, 0.0, 1.0 ], color: [0.0, 0.0, 1.0] },
- ];
- //Identity Matrix
- const TRANSFORM: Transform = Transform {
- transform: [[1.0, 0.0, 0.0, 0.0],
- [0.0, 1.0, 0.0, 0.0],
- [0.0, 0.0, 1.0, 0.0],
- [0.0, 0.0, 0.0, 1.0]]
- };
- let (vertex_buffer, slice) = factory.create_vertex_buffer_with_slice(&TRIANGLE, ());
- let transform_buffer = factory.create_constant_buffer(1);
- let data = pipe::Data {
- vbuf: vertex_buffer,
- transform: transform_buffer,
- out: color_view.clone(),
- };
- let mut running = true;
- while running {
- events_loop.poll_events(|event| {
- if let glutin::Event::WindowEvent { event, .. } = event {
- match event {
- glutin::WindowEvent::Closed |
- glutin::WindowEvent::KeyboardInput {
- input: glutin::KeyboardInput {
- virtual_keycode: Some(glutin::VirtualKeyCode::Escape), ..
- }, ..
- } => running = false,
- _ => {}
- }
- }
- });
- window.swap_buffers().unwrap();
- device.cleanup();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement