show tracked avatar tile
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
extern crate vrtue;
|
||||
use vrtue::*;
|
||||
use vrtue::{tile, vr};
|
||||
use vrtue::vr::AsMatrix4;
|
||||
|
||||
extern crate env_logger;
|
||||
@@ -10,7 +10,7 @@ extern crate nalgebra as na;
|
||||
extern crate num_traits;
|
||||
extern crate piston_window;
|
||||
|
||||
use gfx::Device;
|
||||
use gfx::{tex, Device, Factory};
|
||||
use gfx::traits::FactoryExt;
|
||||
use na::Inverse;
|
||||
use num_traits::identities::One;
|
||||
@@ -25,7 +25,7 @@ const FAR: f32 = 1000.0;
|
||||
gfx_defines!{
|
||||
vertex Vertex {
|
||||
pos: [f32; 3] = "a_pos",
|
||||
color: [f32; 3] = "a_color",
|
||||
uv: [f32; 2] = "a_uv",
|
||||
}
|
||||
|
||||
constant Trans {
|
||||
@@ -35,18 +35,20 @@ gfx_defines!{
|
||||
pipeline pipe {
|
||||
vbuf: gfx::VertexBuffer<Vertex> = (),
|
||||
trans: gfx::ConstantBuffer<Trans> = "b_trans",
|
||||
tiles: gfx::TextureSampler<[f32; 4]> = "t_tiles",
|
||||
pixcolor: gfx::RenderTarget<ColorFormat> = "pixcolor",
|
||||
depth: gfx::DepthTarget<DepthFormat> = gfx::preset::depth::LESS_EQUAL_WRITE,
|
||||
}
|
||||
}
|
||||
|
||||
const POLYGON: [Vertex; 4] = [
|
||||
Vertex { pos: [ -0.25, -0.25, 0. ], color: [1.0, 0.0, 0.0] },
|
||||
Vertex { pos: [ 0.25, -0.25, 0. ], color: [0.0, 1.0, 0.0] },
|
||||
Vertex { pos: [ 0.25, 0.25, 0. ], color: [0.0, 1.0, 0.0] },
|
||||
Vertex { pos: [ -0.25, 0.25, 0. ], color: [0.0, 0.0, 1.0] }
|
||||
Vertex { pos: [ -0.25, -0.25, 0. ], uv: [0., 0.] },
|
||||
Vertex { pos: [ 0.25, -0.25, 0. ], uv: [1., 0.] },
|
||||
Vertex { pos: [ 0.25, 0.25, 0. ], uv: [1., 1.] },
|
||||
Vertex { pos: [ -0.25, 0.25, 0. ], uv: [0., 1.] }
|
||||
];
|
||||
const POLYGON_IDX: &'static [u16] = &[ 0, 1, 2, 2, 3, 0 ];
|
||||
const POLYGON_IDX: &'static [u16] = &[ 0, 1, 2,
|
||||
2, 3, 0 ];
|
||||
|
||||
fn main() {
|
||||
env_logger::init().expect("env logger");
|
||||
@@ -70,21 +72,29 @@ fn main() {
|
||||
.expect("create right renderbuffer");
|
||||
let (vertex_buffer, slice) = window.factory.create_vertex_buffer_with_slice(&POLYGON, POLYGON_IDX);
|
||||
|
||||
let tiles = tile::get_tiles::<_, _, ColorFormat>(&mut window.factory);
|
||||
let nn_sampler = window.factory.create_sampler(
|
||||
tex::SamplerInfo::new(tex::FilterMethod::Scale,
|
||||
tex::WrapMode::Clamp));
|
||||
|
||||
let pipe_monitor = pipe::Data {
|
||||
vbuf: vertex_buffer.clone(),
|
||||
trans: window.factory.create_constant_buffer(1),
|
||||
tiles: (tiles.clone(), nn_sampler.clone()),
|
||||
pixcolor: window.output_color.clone(),
|
||||
depth: window.output_stencil.clone(),
|
||||
};
|
||||
let pipe_left = pipe::Data {
|
||||
vbuf: vertex_buffer.clone(),
|
||||
trans: window.factory.create_constant_buffer(1),
|
||||
tiles: (tiles.clone(), nn_sampler.clone()),
|
||||
pixcolor: tgt_left,
|
||||
depth: depth_left,
|
||||
};
|
||||
let pipe_right = pipe::Data {
|
||||
vbuf: vertex_buffer.clone(),
|
||||
trans: window.factory.create_constant_buffer(1),
|
||||
tiles: (tiles.clone(), nn_sampler.clone()),
|
||||
pixcolor: tgt_right,
|
||||
depth: depth_right,
|
||||
};
|
||||
@@ -180,14 +190,15 @@ const VERTEX_SHADER_SRC: &'static [u8] = br#"
|
||||
#version 140
|
||||
|
||||
in vec3 a_pos;
|
||||
in vec3 a_color;
|
||||
in vec2 a_uv;
|
||||
out vec3 v_color;
|
||||
out vec2 v_uv;
|
||||
uniform b_trans {
|
||||
mat4 u_matrix;
|
||||
};
|
||||
|
||||
void main() {
|
||||
v_color = a_color;
|
||||
v_uv = a_uv;
|
||||
gl_Position = u_matrix * vec4(a_pos, 1.0);
|
||||
}
|
||||
"#;
|
||||
@@ -196,9 +207,12 @@ const FRAGMENT_SHADER_SRC: &'static [u8] = br#"
|
||||
#version 140
|
||||
|
||||
in vec3 v_color;
|
||||
in vec2 v_uv;
|
||||
out vec4 pixcolor;
|
||||
uniform sampler2D t_tiles;
|
||||
|
||||
void main() {
|
||||
pixcolor = vec4(v_color, 1.0);
|
||||
vec2 uv = vec2(v_uv.x, 31.0 / 256 + (1.0 - v_uv.y) / 256.0);
|
||||
pixcolor = texture(t_tiles, uv);
|
||||
}
|
||||
"#;
|
||||
|
||||
@@ -3,4 +3,5 @@
|
||||
#[macro_use] extern crate log;
|
||||
|
||||
pub mod ega;
|
||||
pub mod tile;
|
||||
pub mod vr;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#![feature(conservative_impl_trait)]
|
||||
|
||||
extern crate itertools;
|
||||
extern crate memmap;
|
||||
|
||||
@@ -8,6 +10,7 @@ use itertools::Itertools;
|
||||
use memmap::{Mmap, Protection};
|
||||
|
||||
mod arena;
|
||||
mod ega;
|
||||
mod tile;
|
||||
mod town;
|
||||
mod transpose;
|
||||
|
||||
28
src/tile.rs
28
src/tile.rs
@@ -1,8 +1,36 @@
|
||||
extern crate gfx;
|
||||
|
||||
use ega;
|
||||
|
||||
use ::std;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
|
||||
use self::gfx::tex;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Tile {
|
||||
val: u8,
|
||||
}
|
||||
|
||||
pub fn get_tiles<R, F, T>(factory: &mut F) -> (//gfx::handle::Texture<R, T::Surface>,
|
||||
gfx::handle::ShaderResourceView<R, T::View>)
|
||||
where R: gfx::Resources,
|
||||
F: gfx::Factory<R>,
|
||||
T: gfx::format::TextureFormat {
|
||||
let filename = "data/SHAPES.EGA";
|
||||
let mut file = std::fs::File::open(Path::new(filename))
|
||||
.expect(&format!("failed opening tiles file: {}", filename));
|
||||
let mut ega_vec = Vec::new();
|
||||
file.read_to_end(&mut ega_vec).expect("Read tiles file");
|
||||
let ega_page = ega::decode(&ega_vec, ega::Compression::UNCOMPRESSED, ega::Tiling::TILED(16));
|
||||
let tex = factory.create_texture_const_u8::<T>(tex::Kind::D2(16, 16 * 256,
|
||||
tex::AaMode::Single),
|
||||
&[&ega_page.data])
|
||||
.expect("create tile texture");
|
||||
tex.1
|
||||
}
|
||||
|
||||
impl Tile {
|
||||
pub fn as_char(&self) -> char {
|
||||
match self.val {
|
||||
|
||||
Reference in New Issue
Block a user