Struct tiny_game_framework::Renderer

source ·
pub struct Renderer {
    pub meshes: HashMap<String, Mesh>,
    pub instance_meshes: HashMap<String, InstanceMesh>,
}

Fields§

§meshes: HashMap<String, Mesh>§instance_meshes: HashMap<String, InstanceMesh>

Implementations§

source§

impl Renderer

source

pub fn new() -> Self

Examples found in repository?
examples/rotation.rs (line 7)
4
5
6
7
8
9
10
11
12
13
14
15
16
fn main() {
    let resolution = vec2(500., 500.);
    let mut el = EventLoop::new(resolution.x as u32, resolution.y as u32);
    let mut renderer = Renderer::new();

    while !el.window.should_close() {
        el.update();

        unsafe {
            renderer.draw(&el);
        }
    }
}
More examples
Hide additional examples
examples/test_scene.rs (line 7)
4
5
6
7
8
9
10
11
12
13
14
15
16
fn main() {
    let resolution = vec2(500., 500.);
    let mut el = EventLoop::new(resolution.x as u32, resolution.y as u32);
    let mut renderer = Renderer::new();

    while !el.window.should_close() {
        el.update();

        unsafe {
            renderer.draw(&el);
        }
    }
}
examples/verlet_physics.rs (line 14)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
fn main() {
    let mut el = EventLoop::new(500, 500);
    let mut renderer = Renderer::new();

    let mut world = World::new(&mut renderer);

    let mut dt = 0.0;
    while !el.window.should_close() {
        let now = std::time::Instant::now();
        el.update();

        world.update(&mut renderer, dt, &el);
        
        unsafe {
            gl::Clear(gl::COLOR_BUFFER_BIT);
            renderer.draw(&el);
        }

        dt = now.elapsed().as_secs_f32();
    }
}
source

pub unsafe fn draw(&self, el: &EventLoop)

Examples found in repository?
examples/rotation.rs (line 13)
4
5
6
7
8
9
10
11
12
13
14
15
16
fn main() {
    let resolution = vec2(500., 500.);
    let mut el = EventLoop::new(resolution.x as u32, resolution.y as u32);
    let mut renderer = Renderer::new();

    while !el.window.should_close() {
        el.update();

        unsafe {
            renderer.draw(&el);
        }
    }
}
More examples
Hide additional examples
examples/test_scene.rs (line 13)
4
5
6
7
8
9
10
11
12
13
14
15
16
fn main() {
    let resolution = vec2(500., 500.);
    let mut el = EventLoop::new(resolution.x as u32, resolution.y as u32);
    let mut renderer = Renderer::new();

    while !el.window.should_close() {
        el.update();

        unsafe {
            renderer.draw(&el);
        }
    }
}
examples/verlet_physics.rs (line 27)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
fn main() {
    let mut el = EventLoop::new(500, 500);
    let mut renderer = Renderer::new();

    let mut world = World::new(&mut renderer);

    let mut dt = 0.0;
    while !el.window.should_close() {
        let now = std::time::Instant::now();
        el.update();

        world.update(&mut renderer, dt, &el);
        
        unsafe {
            gl::Clear(gl::COLOR_BUFFER_BIT);
            renderer.draw(&el);
        }

        dt = now.elapsed().as_secs_f32();
    }
}
source§

impl Renderer

source

pub fn add_mesh_from_vertices_and_indices( &mut self, name: &str, vertices: Vec<Vertex>, indices: Vec<u32> ) -> Result<(), String>

source

pub fn add_mesh(&mut self, name: &str, mesh: Mesh) -> Result<(), String>

source

pub fn get_mesh_mut(&mut self, name: &str) -> Option<&mut Mesh>

Examples found in repository?
examples/verlet_physics.rs (line 129)
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
    pub fn new(p: Vec3, name: &str, renderer: &mut Renderer, radius: f32) -> Self {
        let n = Vec3::ZERO;

        let circle = Circle::new(7, radius / 250.0, vec4(rand_betw(0.0, 1.0), rand_betw(0.0, 1.0), rand_betw(0.0, 1.0), 1.0));
        circle.add_to_renderer(name, renderer);
        renderer.get_mesh_mut(name).unwrap().rotation = Quat::from_euler(EulerRot::XYZ, 0.0, 0.0, rand_betw(0.0, 2.0*std::f32::consts::PI));

        Self {
            p,
            op: p,
            v: n,

            r: radius,

            name: name.to_string(),
        }
    }

    pub fn update(&mut self, dt: f32) {
        self.v = self.p - self.op;
        self.op = self.p;
        self.p += self.v + GRAVITY * dt;
    }

    pub fn check_with(&self, particle: &Particle) -> bool {
        if self.p.distance(particle.p) < self.r * 2.0 {
            true
        } else {
            false
        }
    }

    pub fn constrain(&mut self, el: &EventLoop) {
        let (w, h) = el.window.get_framebuffer_size();
        let (hw, hh) = (w as f32 / 2.0, h as f32 / 2.0);

        if self.p.x >= hw - self.r || self.p.x <= -hw + self.r {
            self.p.x = self.p.x.clamp(-hw + self.r, hw - self.r);
            self.v.x = -self.v.x * 0.8;
            self.op.x = self.p.x - self.v.x;
        }

        if self.p.y >= hh - self.r || self.p.y <= -hh + self.r {
            self.p.y = self.p.y.clamp(-hh + self.r, hh - self.r);
            self.v.y = -self.v.y * 0.8;
            self.op.y = self.p.y - self.v.y;
        }
    }

    pub fn update_mesh(&self, renderer: &mut Renderer) {
        if let Some(mesh) = renderer.get_mesh_mut(&self.name) {
            mesh.position.x = lerp(mesh.position.x, self.p.x, 0.5);
            mesh.position.y = lerp(mesh.position.y, self.p.y, 0.5);
        }
    }
source

pub fn get_mesh(&self, name: &str) -> Option<&Mesh>

source

pub fn destroy_mesh(&mut self, name: &str) -> Result<(), String>

source§

impl Renderer

source

pub fn add_instance_mesh( &mut self, name: &str, mesh: InstanceMesh ) -> Result<(), String>

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
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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V