show tracked avatar tile
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
extern crate vrtue;
|
extern crate vrtue;
|
||||||
use vrtue::*;
|
use vrtue::{tile, vr};
|
||||||
use vrtue::vr::AsMatrix4;
|
use vrtue::vr::AsMatrix4;
|
||||||
|
|
||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
@@ -10,7 +10,7 @@ extern crate nalgebra as na;
|
|||||||
extern crate num_traits;
|
extern crate num_traits;
|
||||||
extern crate piston_window;
|
extern crate piston_window;
|
||||||
|
|
||||||
use gfx::Device;
|
use gfx::{tex, Device, Factory};
|
||||||
use gfx::traits::FactoryExt;
|
use gfx::traits::FactoryExt;
|
||||||
use na::Inverse;
|
use na::Inverse;
|
||||||
use num_traits::identities::One;
|
use num_traits::identities::One;
|
||||||
@@ -25,7 +25,7 @@ const FAR: f32 = 1000.0;
|
|||||||
gfx_defines!{
|
gfx_defines!{
|
||||||
vertex Vertex {
|
vertex Vertex {
|
||||||
pos: [f32; 3] = "a_pos",
|
pos: [f32; 3] = "a_pos",
|
||||||
color: [f32; 3] = "a_color",
|
uv: [f32; 2] = "a_uv",
|
||||||
}
|
}
|
||||||
|
|
||||||
constant Trans {
|
constant Trans {
|
||||||
@@ -35,18 +35,20 @@ gfx_defines!{
|
|||||||
pipeline pipe {
|
pipeline pipe {
|
||||||
vbuf: gfx::VertexBuffer<Vertex> = (),
|
vbuf: gfx::VertexBuffer<Vertex> = (),
|
||||||
trans: gfx::ConstantBuffer<Trans> = "b_trans",
|
trans: gfx::ConstantBuffer<Trans> = "b_trans",
|
||||||
|
tiles: gfx::TextureSampler<[f32; 4]> = "t_tiles",
|
||||||
pixcolor: gfx::RenderTarget<ColorFormat> = "pixcolor",
|
pixcolor: gfx::RenderTarget<ColorFormat> = "pixcolor",
|
||||||
depth: gfx::DepthTarget<DepthFormat> = gfx::preset::depth::LESS_EQUAL_WRITE,
|
depth: gfx::DepthTarget<DepthFormat> = gfx::preset::depth::LESS_EQUAL_WRITE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const POLYGON: [Vertex; 4] = [
|
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. ], uv: [0., 0.] },
|
||||||
Vertex { pos: [ 0.25, -0.25, 0. ], color: [0.0, 1.0, 0.0] },
|
Vertex { pos: [ 0.25, -0.25, 0. ], uv: [1., 0.] },
|
||||||
Vertex { pos: [ 0.25, 0.25, 0. ], color: [0.0, 1.0, 0.0] },
|
Vertex { pos: [ 0.25, 0.25, 0. ], uv: [1., 1.] },
|
||||||
Vertex { pos: [ -0.25, 0.25, 0. ], color: [0.0, 0.0, 1.0] }
|
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() {
|
fn main() {
|
||||||
env_logger::init().expect("env logger");
|
env_logger::init().expect("env logger");
|
||||||
@@ -70,21 +72,29 @@ fn main() {
|
|||||||
.expect("create right renderbuffer");
|
.expect("create right renderbuffer");
|
||||||
let (vertex_buffer, slice) = window.factory.create_vertex_buffer_with_slice(&POLYGON, POLYGON_IDX);
|
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 {
|
let pipe_monitor = pipe::Data {
|
||||||
vbuf: vertex_buffer.clone(),
|
vbuf: vertex_buffer.clone(),
|
||||||
trans: window.factory.create_constant_buffer(1),
|
trans: window.factory.create_constant_buffer(1),
|
||||||
|
tiles: (tiles.clone(), nn_sampler.clone()),
|
||||||
pixcolor: window.output_color.clone(),
|
pixcolor: window.output_color.clone(),
|
||||||
depth: window.output_stencil.clone(),
|
depth: window.output_stencil.clone(),
|
||||||
};
|
};
|
||||||
let pipe_left = pipe::Data {
|
let pipe_left = pipe::Data {
|
||||||
vbuf: vertex_buffer.clone(),
|
vbuf: vertex_buffer.clone(),
|
||||||
trans: window.factory.create_constant_buffer(1),
|
trans: window.factory.create_constant_buffer(1),
|
||||||
|
tiles: (tiles.clone(), nn_sampler.clone()),
|
||||||
pixcolor: tgt_left,
|
pixcolor: tgt_left,
|
||||||
depth: depth_left,
|
depth: depth_left,
|
||||||
};
|
};
|
||||||
let pipe_right = pipe::Data {
|
let pipe_right = pipe::Data {
|
||||||
vbuf: vertex_buffer.clone(),
|
vbuf: vertex_buffer.clone(),
|
||||||
trans: window.factory.create_constant_buffer(1),
|
trans: window.factory.create_constant_buffer(1),
|
||||||
|
tiles: (tiles.clone(), nn_sampler.clone()),
|
||||||
pixcolor: tgt_right,
|
pixcolor: tgt_right,
|
||||||
depth: depth_right,
|
depth: depth_right,
|
||||||
};
|
};
|
||||||
@@ -180,14 +190,15 @@ const VERTEX_SHADER_SRC: &'static [u8] = br#"
|
|||||||
#version 140
|
#version 140
|
||||||
|
|
||||||
in vec3 a_pos;
|
in vec3 a_pos;
|
||||||
in vec3 a_color;
|
in vec2 a_uv;
|
||||||
out vec3 v_color;
|
out vec3 v_color;
|
||||||
|
out vec2 v_uv;
|
||||||
uniform b_trans {
|
uniform b_trans {
|
||||||
mat4 u_matrix;
|
mat4 u_matrix;
|
||||||
};
|
};
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
v_color = a_color;
|
v_uv = a_uv;
|
||||||
gl_Position = u_matrix * vec4(a_pos, 1.0);
|
gl_Position = u_matrix * vec4(a_pos, 1.0);
|
||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
@@ -196,9 +207,12 @@ const FRAGMENT_SHADER_SRC: &'static [u8] = br#"
|
|||||||
#version 140
|
#version 140
|
||||||
|
|
||||||
in vec3 v_color;
|
in vec3 v_color;
|
||||||
|
in vec2 v_uv;
|
||||||
out vec4 pixcolor;
|
out vec4 pixcolor;
|
||||||
|
uniform sampler2D t_tiles;
|
||||||
|
|
||||||
void main() {
|
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;
|
#[macro_use] extern crate log;
|
||||||
|
|
||||||
pub mod ega;
|
pub mod ega;
|
||||||
|
pub mod tile;
|
||||||
pub mod vr;
|
pub mod vr;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#![feature(conservative_impl_trait)]
|
||||||
|
|
||||||
extern crate itertools;
|
extern crate itertools;
|
||||||
extern crate memmap;
|
extern crate memmap;
|
||||||
|
|
||||||
@@ -8,6 +10,7 @@ use itertools::Itertools;
|
|||||||
use memmap::{Mmap, Protection};
|
use memmap::{Mmap, Protection};
|
||||||
|
|
||||||
mod arena;
|
mod arena;
|
||||||
|
mod ega;
|
||||||
mod tile;
|
mod tile;
|
||||||
mod town;
|
mod town;
|
||||||
mod transpose;
|
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)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct Tile {
|
pub struct Tile {
|
||||||
val: u8,
|
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 {
|
impl Tile {
|
||||||
pub fn as_char(&self) -> char {
|
pub fn as_char(&self) -> char {
|
||||||
match self.val {
|
match self.val {
|
||||||
|
|||||||
Reference in New Issue
Block a user