Skip to content

Commit

Permalink
Get an image on screen, in the wrong spot
Browse files Browse the repository at this point in the history
  • Loading branch information
Xaeroxe committed Oct 27, 2017
1 parent 276b8a6 commit 27dfdb9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 29 deletions.
4 changes: 2 additions & 2 deletions amethyst_ui/src/frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ in VertexData {
out vec4 color;

void main() {
color = vec4(1.0, 0.0, 0.0, 1.0);
//color = texture(albedo, vertex.tex_coord);
//color = vec4(1.0, 0.0, 0.0, 1.0);
color = texture(albedo, vertex.tex_coord);
}
33 changes: 10 additions & 23 deletions amethyst_ui/src/pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use std::cmp::{Ordering, PartialOrd};

use amethyst_assets::{AssetStorage, Loader};
use cgmath::{Matrix4, Ortho};
use gfx::preset::blend;
use gfx::pso::buffer::ElemStride;
use gfx::state::ColorMask;
Expand Down Expand Up @@ -31,7 +30,6 @@ const FRAG_SRC: &[u8] = include_bytes!("frag.glsl");
#[allow(dead_code)] // This is used by the shaders
#[repr(C)]
struct VertexArgs {
proj: [[f32; 4]; 4],
coord: [f32; 2],
dimension: [f32; 2],
screen_dimensions: [f32; 2],
Expand All @@ -54,29 +52,29 @@ where
// Initialize a single unit quad, we'll use this mesh when drawing quads later
let data = vec![
PosTex {
position: [0., 0., 0.],
position: [-1., 0., 0.],
tex_coord: [0., 0.],
},
PosTex {
position: [0., 1., 0.],
position: [0., 0., 0.],
tex_coord: [1., 0.],
},
PosTex {
position: [-1., 1., 0.],
tex_coord: [0., 1.],
},
PosTex {
position: [1., 1., 0.],
tex_coord: [1., 1.],
position: [-1., 1., 0.],
tex_coord: [0., 1.],
},
PosTex {
position: [0., 0., 0.],
tex_coord: [0., 0.],
tex_coord: [1., 0.],
},
PosTex {
position: [1., 1., 0.],
position: [0., 1., 0.],
tex_coord: [1., 1.],
},
PosTex {
position: [1., 0., 0.],
tex_coord: [1., 0.],
},
].into();
let mesh_handle = loader.load_from_data(data, mesh_storage);
DrawUi {
Expand Down Expand Up @@ -219,15 +217,6 @@ impl<'a> ParallelIterator for DrawUiApply<'a> {
let mut bitset = BitSet::new();
bitset.add(0);

let proj = Ortho {
left: -screen_dimensions.width() / 2.0,
right: screen_dimensions.width() / 2.0,
bottom: -screen_dimensions.height() / 2.0,
top: screen_dimensions.height() / 2.0,
near: 0.1,
far: 2000.0,
};

let cached_draw_order = &cached_draw_order;

supplier
Expand All @@ -245,10 +234,8 @@ impl<'a> ParallelIterator for DrawUiApply<'a> {
};

if let Some(image) = tex_storage.get(&ui_image.texture) {
let proj: Matrix4<f32> = proj.into();

let vertex_args = VertexArgs {
proj: proj.into(),
coord: [ui_transform.x, ui_transform.y],
dimension: [ui_transform.width, ui_transform.height],
screen_dimensions: [
Expand Down
5 changes: 2 additions & 3 deletions amethyst_ui/src/vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#version 150 core

layout (std140) uniform VertexArgs {
uniform mat4 proj;
uniform vec2 coord;
uniform vec2 dimension;
uniform vec2 screen_dimensions;
Expand All @@ -18,7 +17,7 @@ out VertexData {
} vertex;

void main() {
vertex.position = vec4(position * vec3(dimension / screen_dimensions, 1.0) + vec3(coord / screen_dimensions, 0.0), -1.0) * 2.0 - 1.0;
vertex.position = vec4(position, 1.0);
vertex.tex_coord = tex_coord;
gl_Position = proj * vertex.position;
gl_Position = vertex.position;
}
2 changes: 1 addition & 1 deletion examples/09_ui/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl State for Example {
initialise_camera(&mut engine.world);

let logo = engine.world.read_resource::<Loader>().load(
"texture/logo.png",
"texture/logo_transparent.png",
PngFormat,
Default::default(),
(),
Expand Down
Binary file added examples/assets/texture/logo_transparent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 27dfdb9

Please sign in to comment.