pub struct Texture { /* private fields */ }Expand description
Contains all the information need to render an image/texture to the screen. In order to be used it must be put inside a Material
Implementations§
Source§impl Texture
impl Texture
Sourcepub fn new<P>(
engine: &mut Engine,
path: P,
loading_op: LoadingOp,
) -> ResourceId<Texture>
pub fn new<P>( engine: &mut Engine, path: P, loading_op: LoadingOp, ) -> ResourceId<Texture>
Attempts to both read a file at the specified path and turn it into an image.
Examples found in repository?
examples/rectangles.rs (line 15)
12fn main() {
13 let mut engine = EngineBuilder::new().build().unwrap();
14
15 let texture = Texture::new(&mut engine, "examples/bplogo.png", LoadingOp::Blocking);
16
17 let texture_material = MaterialBuilder::new()
18 .add_texture(texture)
19 .build(&mut engine);
20 let regular_material = MaterialBuilder::new().build(&mut engine);
21
22 let pos = Position {
23 pos: vec2! { 0.0 },
24 regular_material,
25 texture_material,
26 state: false,
27 };
28
29 engine.run(pos);
30}
31
32struct Position {
33 pos: Vec2<f32>,
34 regular_material: Material,
35 texture_material: Material,
36 state: bool,
37}
38
39impl Game for Position {
40 fn render<'o>(&'o mut self, mut render: RenderHandle<'o>) {
41 let mut render_handle = render.begin_pass(Colour::BLACK);
42
43 let defualt_size = vec2! { 50.0 };
44 self.regular_material.add_rectangle(
45 vec2! { 0.0 },
46 defualt_size,
47 Colour::RED,
48 &render_handle,
49 );
50 self.regular_material
51 .add_rectangle(self.pos, vec2! { 100.0 }, Colour::RED, &render_handle);
52 self.texture_material.add_rectangle(
53 vec2! { 0.0, 50.0 },
54 defualt_size,
55 Colour::WHITE,
56 &render_handle,
57 );
58 self.texture_material.add_rectangle_with_uv(
59 Vec2 { x: 0.0, y: 100.0 },
60 defualt_size,
61 vec2! { 311.0 },
62 vec2! { 311.0 },
63 Colour::WHITE,
64 &render_handle,
65 );
66 self.regular_material.add_rectangle_with_rotation(
67 Vec2 { x: 0.0, y: 150.0 },
68 defualt_size,
69 Colour::GREEN,
70 45.0,
71 &render_handle,
72 );
73
74 let points = [
75 Vec2 { x: 0.0, y: 300.0 },
76 Vec2 { x: 80.0, y: 290.0 },
77 Vec2 { x: 100.0, y: 400.0 },
78 Vec2 { x: 60.0, y: 400.0 },
79 ];
80 let uvs = [
81 vec2! { 0.0 },
82 Vec2 { x: 1.0, y: 0.0 },
83 vec2! { 1.0 },
84 Vec2 { x: 0.0, y: 1.0 },
85 ];
86
87 self.regular_material
88 .add_custom(points, uvs, 0.0, Colour::RED, &render_handle);
89
90 self.regular_material.add_screenspace_rectangle(
91 vec2!(0.0, 0.0),
92 vec2!(1.0),
93 Colour::YELLOW,
94 &render_handle,
95 );
96
97 if self.state {
98 self.regular_material.add_rectangle(
99 vec2!(300.0),
100 vec2!(100.0),
101 Colour::GREEN,
102 &render_handle,
103 );
104 }
105
106 self.texture_material.draw(&mut render_handle);
107 self.regular_material.draw(&mut render_handle);
108 }
109
110 fn update(&mut self, engine_handle: &mut Engine) {
111 let dt = engine_handle.get_frame_delta_time();
112 self.pos.x += 100.0 * dt;
113 if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
114 let new_texture = Texture::new(
115 engine_handle,
116 "examples/eggshark.png",
117 LoadingOp::Background,
118 );
119 self.texture_material.change_texture(new_texture);
120 }
121
122 self.state = engine_handle.is_key_down(Key::Space);
123 }More examples
examples/camera.rs (line 16)
13fn main() {
14 let mut engine = EngineBuilder::new().build().unwrap();
15
16 let texture = Texture::new(&mut engine, "examples/bplogo.png", LoadingOp::Blocking);
17
18 let material = MaterialBuilder::new()
19 .add_texture(texture)
20 .build(&mut engine);
21
22 let camera = Camera::default();
23
24 let text = TextMaterial::new(
25 "Mouse pos: 0,0 \n Mouse pos: 0, 0",
26 Colour::WHITE,
27 15.0,
28 20.0,
29 );
30
31 let game = CameraExample {
32 material,
33 text,
34 camera,
35 };
36
37 engine.run(game);
38}examples/texture.rs (line 19)
12fn main() {
13 let mut engine = EngineBuilder::new()
14 .set_window_title("Testing Triangle")
15 .with_resolution((400, 400))
16 .build()
17 .unwrap();
18
19 let texture = Texture::new(&mut engine, "examples/bplogo.png", LoadingOp::Blocking);
20
21 let texture = MaterialBuilder::new()
22 .add_texture(texture)
23 .build(&mut engine);
24 let defualt = MaterialBuilder::new().build(&mut engine);
25
26 let s = TextureExample {
27 current: texture,
28 other: defualt,
29 pos: vec2! { 0.0 },
30 };
31
32 engine.run(s);
33}Sourcepub fn new_with_sampler<P>(
engine: &mut Engine,
path: P,
sampler: SamplerType,
loading_op: LoadingOp,
) -> ResourceId<Texture>
pub fn new_with_sampler<P>( engine: &mut Engine, path: P, sampler: SamplerType, loading_op: LoadingOp, ) -> ResourceId<Texture>
Attempts to both read a file at the specified path and turn it into an image.
Sourcepub fn new_with_mag_min_sampler<P>(
engine: &mut Engine,
path: P,
mag_sampler: SamplerType,
min_sampler: SamplerType,
loading_op: LoadingOp,
) -> ResourceId<Texture>
pub fn new_with_mag_min_sampler<P>( engine: &mut Engine, path: P, mag_sampler: SamplerType, min_sampler: SamplerType, loading_op: LoadingOp, ) -> ResourceId<Texture>
Attempts to load the file at the path and then turn it into a texture. This also allows you to select what sampling type to use
for both the mag_sampler, when the texture is being drawn larger than the orignal resolution and min_sampler, when the texture
is being drawn smaller than the original resolution.
Auto Trait Implementations§
impl Freeze for Texture
impl !RefUnwindSafe for Texture
impl Send for Texture
impl Sync for Texture
impl Unpin for Texture
impl !UnwindSafe for Texture
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more