Struct Point2

Source
pub struct Point2 {
    pub x: i32,
    pub y: i32,
}

Fields§

§x: i32§y: i32

Implementations§

Source§

impl Point2

Source

pub const ZERO: Self

Source

pub const ONE: Self

Source

pub fn new<T: ToPrimitive>(x: T, y: T) -> Self

Examples found in repository?
examples/software.rs (line 9)
6fn main() {
7    let mut runner = est_render::runner::new().expect("Failed to create runner");
8    let mut window = runner
9        .create_window("Engine Example", Point2::new(800, 600))
10        .build()
11        .expect("Failed to create window");
12
13    let mut sw = est_render::software::new(Some(&mut window))
14        .build()
15        .expect("Failed to create pixel buffer");
16
17    let mut pixels = vec![128u32; (800 * 600) as usize];
18    let mut size_px = Point2::new(800.0, 600.0);
19
20    while runner.pool_events(None) {
21        for event in runner.get_events() {
22            match event {
23                Event::WindowClosed { .. } => {
24                    return;
25                }
26                Event::WindowResized { size, .. } => {
27                    pixels.resize((size.x * size.y) as usize, 128);
28                    size_px = Point2::new(size.x as f32, size.y as f32);
29                }
30                _ => {}
31            }
32        }
33
34        if let Err(e) = sw.write_buffers(&pixels, size_px) {
35            eprintln!("Error writing buffers: {}", e);
36        }
37    }
38}
More examples
Hide additional examples
examples/clear_color.rs (line 9)
5fn main() {
6    let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8    let mut window = runner
9        .create_window("Clear Color Example", Point2::new(800, 600))
10        .build()
11        .expect("Failed to create window");
12
13    let mut gpu = est_render::gpu::new(Some(&mut window))
14        .build()
15        .expect("Failed to create GPU");
16
17    while runner.pool_events(None) {
18        for event in runner.get_events() {
19            match event {
20                Event::WindowClosed { .. } => {
21                    return;
22                }
23                _ => {}
24            }
25        }
26
27        if let Ok(mut cmd) = gpu.begin_command() {
28            let surface = cmd.get_surface_texture();
29            if surface.is_err() {
30                println!("Failed to get surface texture: {:?}", surface.err());
31                continue;
32            }
33
34            // Or you could use `cmd.begin_renderpass()` directly
35            if let Ok(mut rp) = cmd.renderpass_builder()
36                .add_surface_color_attachment(surface.as_ref().unwrap(), Some(&BlendState::ALPHA_BLEND))
37                .build() 
38            {
39                rp.set_clear_color(Color::BLUE);
40            }
41        }
42    }
43}
examples/gpu_adapter.rs (line 8)
5fn main() {
6    let mut runner = est_render::runner::new().expect("Failed to create runner");
7    let mut window = runner
8        .create_window("Engine Example", Point2::new(800, 600))
9        .build()
10        .expect("Failed to create window");
11
12    let adapters = est_render::gpu::query_gpu_adapter(Some(&window));
13    if adapters.is_empty() {
14        eprintln!("No GPU adapters found. Exiting.");
15        return;
16    }
17
18    let selected_adapter = adapters
19        .iter()
20        .find(|adapter| adapter.backend_enum == AdapterBackend::Vulkan)
21        .cloned();
22
23    if selected_adapter.is_none() {
24        eprintln!("No suitable GPU adapter found. Exiting.");
25        return;
26    }
27
28    let adapter = selected_adapter.unwrap();
29    let mut gpu = est_render::gpu::new(Some(&mut window))
30        .set_adapter(&adapter)
31        .build()
32        .expect("Failed to create GPU");
33
34    while runner.pool_events(None) {
35        for event in runner.get_events() {
36            match event {
37                Event::WindowClosed { .. } => {
38                    return;
39                }
40                _ => {}
41            }
42        }
43
44        if let Ok(mut cmd) = gpu.begin_command() {
45            if let Ok(mut rp) = cmd.begin_renderpass() {
46                rp.set_clear_color(Color::LIGHTBLUE);
47            }
48        }
49    }
50}
examples/drawing.rs (line 9)
5fn main() {
6    let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8    let mut window = runner
9        .create_window("Drawing Example", Point2::new(800, 600))
10        .build()
11        .expect("Failed to create window");
12
13    let mut gpu = est_render::gpu::new(Some(&mut window))
14        .build()
15        .expect("Failed to create GPU");
16
17    while runner.pool_events(None) {
18        for event in runner.get_events() {
19            match event {
20                Event::WindowClosed { .. } => {
21                    return;
22                }
23                _ => {}
24            }
25        }
26
27        if let Ok(mut cmd) = gpu.begin_command() {
28            if let Ok(mut gp) = cmd.begin_renderpass() {
29                gp.set_clear_color(Color::BLUE); // Set the clear color to blue
30
31                gp.set_blend(0, Some(&BlendState::ALPHA_BLEND));
32                if let Some(mut drawing) = gp.begin_drawing() {
33                    drawing.draw_rect_filled(
34                        Vector2::new(100.0, 100.0),
35                        Vector2::new(200.0, 200.0),
36                        Color::RED,
37                    );
38
39                    drawing.draw_circle_filled(Vector2::new(400.0, 300.0), 50.0, 25, Color::GREEN);
40                }
41
42                gp.set_blend(0, Some(&BlendState::ADDITIVE_BLEND));
43                if let Some(mut drawing) = gp.begin_drawing() {
44                    drawing.draw_text(
45                        "Hello, World!",
46                        Vector2::new(300.0, 500.0),
47                        Color::WHITE,
48                    );
49                }
50            }
51        }
52    }
53}
examples/font.rs (line 9)
5fn main() {
6    let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8    let mut window = runner
9        .create_window("Font Example", Point2::new(800, 600))
10        .build()
11        .expect("Failed to create window");
12
13    let mut gpu = est_render::gpu::new(Some(&mut window))
14        .build()
15        .expect("Failed to create GPU");
16
17    let mut font_manager = est_render::font::new();
18
19    let font = font_manager
20        .load_font("Arial", None, 20.0)
21        .expect("Failed to load font");
22
23    // Generate baked text texture
24    let texture = font
25        .create_baked_text(&mut gpu, "Hello, World!\nThis is a clear color example.")
26        .expect("Failed to create baked text");
27
28    while runner.pool_events(None) {
29        for event in runner.get_events() {
30            match event {
31                Event::WindowClosed { .. } => {
32                    return;
33                }
34                _ => {}
35            }
36        }
37
38        if let Ok(mut cmd) = gpu.begin_command() {
39            if let Ok(mut gp) = cmd.begin_renderpass() {
40                gp.set_clear_color(Color::BLUE);
41
42                // The best texture blend for font rendering, others may has artifacts like black borders
43                gp.set_blend(0, Some(&BlendState::ADDITIVE_BLEND));
44                
45                if let Some(mut drawing) = gp.begin_drawing() {
46                    let size: Vector2 = texture.size().into();
47
48                    // Baked text rendering
49                    drawing.set_texture(Some(&texture));
50                    drawing.draw_rect_image(Vector2::new(0.0, 0.0), size, Color::WHITE);
51
52                    // Online text rendering
53                    drawing.set_font(&font);
54                    drawing.draw_text(
55                        "Hello, World!\nThis is a clear color example.",
56                        Vector2::new(size.x, 0.0),
57                        Color::WHITE,
58                    );
59                }
60            }
61        }
62    }
63}
examples/texture_atlas.rs (line 9)
5fn main() {
6    let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8    let mut window = runner
9        .create_window("Clear Color Example", Point2::new(800, 600))
10        .build()
11        .expect("Failed to create window");
12
13    let mut gpu = est_render::gpu::new(Some(&mut window))
14        .build()
15        .expect("Failed to create GPU");
16
17    let texture_atlas = gpu
18        .create_texture_atlas()
19        .add_texture_file(
20            "example_texture",
21            "./examples/resources/test1.png",
22        )
23        .add_texture_file(
24            "example_texture2",
25            "./examples/resources/test2.png",
26        )
27        .build()
28        .expect("Failed to create texture atlas");
29
30    while runner.pool_events(None) {
31        for event in runner.get_events() {
32            match event {
33                Event::WindowClosed { .. } => {
34                    return;
35                }
36                _ => {}
37            }
38        }
39
40        if let Ok(mut cmd) = gpu.begin_command() {
41            if let Ok(mut gp) = cmd.begin_renderpass() {
42                gp.set_clear_color(Color::BLUEVIOLET);
43                gp.set_blend(0, Some(&BlendState::NONE));
44
45                if let Some(mut drawing) = gp.begin_drawing() {
46                    drawing.set_texture_atlas(Some((&texture_atlas, "example_texture")));
47                    drawing.draw_rect_image(
48                        Vector2::new(100.0, 100.0),
49                        Vector2::new(200.0, 200.0),
50                        Color::WHITE,
51                    );
52                    drawing.set_texture_atlas(Some((&texture_atlas, "example_texture2")));
53                    drawing.draw_rect_image(
54                        Vector2::new(350.0, 100.0),
55                        Vector2::new(200.0, 200.0),
56                        Color::WHITE,
57                    );
58                    drawing.draw_circle_image(Vector2::new(600.0, 200.0), 100.0, 20, Color::WHITE);
59                }
60            }
61        }
62    }
63}

Trait Implementations§

Source§

impl Clone for Point2

Source§

fn clone(&self) -> Point2

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Point2

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Point2

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<(i32, i32)> for Point2

Source§

fn from(tuple: (i32, i32)) -> Self

Converts to this type from the input type.
Source§

impl From<(u32, u32)> for Point2

Source§

fn from(tuple: (u32, u32)) -> Self

Converts to this type from the input type.
Source§

impl From<PhysicalSize<i32>> for Point2

Source§

fn from(size: PhysicalSize<i32>) -> Self

Converts to this type from the input type.
Source§

impl From<PhysicalSize<u32>> for Point2

Source§

fn from(size: PhysicalSize<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<Point2> for Vector2

Source§

fn from(point: Point2) -> Self

Converts to this type from the input type.
Source§

impl From<Point2> for Vector2I

Source§

fn from(point: Point2) -> Self

Converts to this type from the input type.
Source§

impl From<Vector2> for Point2

Source§

fn from(vector: Vector2) -> Self

Converts to this type from the input type.
Source§

impl From<Vector2I> for Point2

Source§

fn from(vector: Vector2I) -> Self

Converts to this type from the input type.
Source§

impl Into<Extent3d> for Point2

Source§

fn into(self) -> Extent3d

Converts this type into the (usually inferred) input type.
Source§

impl Into<PhysicalSize<i32>> for Point2

Source§

fn into(self) -> PhysicalSize<i32>

Converts this type into the (usually inferred) input type.
Source§

impl Into<PhysicalSize<u32>> for Point2

Source§

fn into(self) -> PhysicalSize<u32>

Converts this type into the (usually inferred) input type.
Source§

impl Ord for Point2

Source§

fn cmp(&self, other: &Point2) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Point2

Source§

fn eq(&self, other: &Point2) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Point2

Source§

fn partial_cmp(&self, other: &Point2) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Point2

Source§

impl Eq for Point2

Source§

impl StructuralPartialEq for Point2

Auto Trait Implementations§

§

impl Freeze for Point2

§

impl RefUnwindSafe for Point2

§

impl Send for Point2

§

impl Sync for Point2

§

impl Unpin for Point2

§

impl UnwindSafe for Point2

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

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>

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)

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)

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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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<T> Upcast<T> for T

Source§

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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