93 lines
2.6 KiB
Rust
93 lines
2.6 KiB
Rust
|
use glium::{
|
||
|
framebuffer::SimpleFrameBuffer, implement_vertex, index::PrimitiveType, uniform,
|
||
|
uniforms::Sampler, IndexBuffer, Surface, VertexBuffer,
|
||
|
};
|
||
|
use resources::Shaders;
|
||
|
|
||
|
use crate::resources::{self, Textures};
|
||
|
|
||
|
use super::GameState;
|
||
|
|
||
|
pub struct TestState;
|
||
|
|
||
|
impl GameState for TestState {
|
||
|
fn input(&mut self, resources: &mut anymap::AnyMap, event: &glium::glutin::event::Event<()>) {}
|
||
|
|
||
|
fn update(&mut self, resources: &mut anymap::AnyMap, dt: f32) -> Option<Box<dyn GameState>> {
|
||
|
None
|
||
|
}
|
||
|
|
||
|
fn render(
|
||
|
&mut self,
|
||
|
resources: &mut anymap::AnyMap,
|
||
|
display: &glium::Display,
|
||
|
target: &mut SimpleFrameBuffer,
|
||
|
) {
|
||
|
// Make vertex buffer
|
||
|
let vertex_buffer = {
|
||
|
#[derive(Clone, Copy)]
|
||
|
struct Vertex {
|
||
|
position: [f32; 2],
|
||
|
tex_coords: [f32; 2],
|
||
|
}
|
||
|
|
||
|
implement_vertex!(Vertex, position, tex_coords);
|
||
|
|
||
|
VertexBuffer::new(
|
||
|
display,
|
||
|
&[
|
||
|
Vertex {
|
||
|
position: [-1.0, -1.0],
|
||
|
tex_coords: [0.0, 0.0],
|
||
|
},
|
||
|
Vertex {
|
||
|
position: [-1.0, 1.0],
|
||
|
tex_coords: [0.0, 1.0],
|
||
|
},
|
||
|
Vertex {
|
||
|
position: [1.0, 1.0],
|
||
|
tex_coords: [1.0, 1.0],
|
||
|
},
|
||
|
Vertex {
|
||
|
position: [1.0, -1.0],
|
||
|
tex_coords: [1.0, 0.0],
|
||
|
},
|
||
|
],
|
||
|
)
|
||
|
.unwrap()
|
||
|
};
|
||
|
|
||
|
let index_buffer =
|
||
|
IndexBuffer::new(display, PrimitiveType::TriangleStrip, &[1 as u16, 2, 0, 3]).unwrap();
|
||
|
|
||
|
let program = resources.get::<Shaders>().unwrap().get("basic").unwrap();
|
||
|
|
||
|
let texture = resources
|
||
|
.get::<Textures>()
|
||
|
.unwrap()
|
||
|
.get("tiles:dirt")
|
||
|
.unwrap();
|
||
|
|
||
|
let uniforms = uniform! {
|
||
|
/*matrix: [
|
||
|
[1.0,0.0,0.0],
|
||
|
[0.0,1.0,0.0],
|
||
|
[0.0,0.0,1.0 as f32],
|
||
|
],*/
|
||
|
matrix: cgmath::conv::array3x3(cgmath::Matrix3::from_nonuniform_scale(1.0/crate::SCREEN_WIDTH*16.0, 1.0/crate::SCREEN_HEIGHT*16.0)),
|
||
|
texture: texture.sampled().magnify_filter(glium::uniforms::MagnifySamplerFilter::Nearest),
|
||
|
|
||
|
};
|
||
|
|
||
|
target
|
||
|
.draw(
|
||
|
&vertex_buffer,
|
||
|
&index_buffer,
|
||
|
program,
|
||
|
&uniforms,
|
||
|
&Default::default(),
|
||
|
)
|
||
|
.unwrap();
|
||
|
}
|
||
|
}
|