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

source

pub fn new<P>(engine: &mut Engine, path: P) -> ResourceId<Texture>
where P: AsRef<Path>,

Attempts to both read a file at the specified path and turn it into an image. This will halt the engine untill loading is finished please see the resource module module for more information on how resource loading works.

Examples found in repository?
examples/rectangles.rs (line 16)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
fn main() {
    let mut engine = EngineBuilder::new()
        .set_clear_colour(Colour::BLACK)
        .build()
        .unwrap();

    let texture = Texture::new(&mut engine, "examples/bplogo.png");

    let texture_material = MaterialBuilder::new()
        .add_texture(texture)
        .build(&mut engine);
    let regular_material = MaterialBuilder::new().build(&mut engine);

    let pos = Position {
        pos: Vec2 { x: 0.0, y: 0.0 },
        regular_material,
        texture_material,
    };

    engine.run(pos);
}

struct Position {
    pos: Vec2<f32>,
    regular_material: Material,
    texture_material: Material,
}

impl Game for Position {
    fn render<'pass, 'others>(
        &'others mut self,
        mut render_handle: RenderInformation<'pass, 'others>,
    ) where
        'others: 'pass,
    {
        let defualt_size = Vec2 { x: 50.0, y: 50.0 };
        self.regular_material.add_rectangle(
            Vec2 { x: 0.0, y: 0.0 },
            defualt_size,
            Colour::RED,
            &render_handle,
        );
        self.regular_material.add_rectangle(
            self.pos,
            Vec2 { x: 100.0, y: 100.0 },
            Colour::RED,
            &render_handle,
        );
        self.texture_material.add_rectangle(
            Vec2 { x: 0.0, y: 50.0 },
            defualt_size,
            Colour::WHITE,
            &render_handle,
        );
        self.texture_material.add_rectangle_with_uv(
            Vec2 { x: 0.0, y: 100.0 },
            defualt_size,
            Vec2 { x: 311.0, y: 311.0 },
            Vec2 { x: 311.0, y: 311.0 },
            Colour::WHITE,
            &render_handle,
        );
        self.regular_material.add_rectangle_with_rotation(
            Vec2 { x: 0.0, y: 150.0 },
            defualt_size,
            Colour::GREEN,
            45.0,
            &render_handle,
        );

        let points = [
            Vec2 { x: 0.0, y: 300.0 },
            Vec2 { x: 80.0, y: 290.0 },
            Vec2 { x: 100.0, y: 400.0 },
            Vec2 { x: 60.0, y: 400.0 },
        ];
        let uvs = [
            Vec2 { x: 0.0, y: 0.0 },
            Vec2 { x: 1.0, y: 0.0 },
            Vec2 { x: 1.0, y: 1.0 },
            Vec2 { x: 0.0, y: 1.0 },
        ];

        self.regular_material
            .add_custom(points, uvs, 0.0, Colour::RED, &render_handle);

        self.texture_material.draw(&mut render_handle);
        self.regular_material.draw(&mut render_handle);
    }

    fn update(&mut self, engine_handle: &mut Engine) {
        let dt = engine_handle.get_frame_delta_time();
        self.pos.x += 100.0 * dt;
        if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
            let new_texture = Texture::new(engine_handle, "examples/eggshark.png");
            self.texture_material.change_texture(new_texture);
        }
    }
More examples
Hide additional examples
examples/texture.rs (line 16)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() {
    let mut engine = EngineBuilder::new()
        .set_window_title("Testing Triangle")
        .with_resolution((400, 400))
        .build()
        .unwrap();

    let texture = Texture::new(&mut engine, "examples/bplogo.png");

    let texture = MaterialBuilder::new()
        .add_texture(texture)
        .build(&mut engine);
    let defualt = MaterialBuilder::new().build(&mut engine);

    let s = TextureExample {
        current: texture,
        other: defualt,
        pos: Vec2 { x: 0.0, y: 0.0 },
    };

    engine.run(s);
}
source

pub fn from_btyes( engine: &mut Engine, label: Option<&str>, bytes: &[u8] ) -> ResourceId<Texture>

Attempts to load an image from a byte array. This is done staticly as it does not halt the engine for more information on resource loading see resource module.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSync for T
where T: Sync,