Struct macroquad::texture::Texture2D[][src]

pub struct Texture2D { /* fields omitted */ }

Texture, data stored in GPU memory

Implementations

impl Texture2D[src]

pub fn empty() -> Texture2D[src]

Creates an empty Texture2D.

Example

let texture = Texture2D::empty();

pub fn from_file_with_format<'a>(
    bytes: &[u8],
    format: Option<ImageFormat>
) -> Texture2D
[src]

Creates a Texture2D from a slice of bytes that contains an encoded image.

If format is None, it will make an educated guess on the ImageFormat.

Example

let texture = Texture2D::from_file_with_format(
    include_bytes!("../examples/rust.png"),
    None,
    );

pub fn from_image(image: &Image) -> Texture2D[src]

Creates a Texture2D from an Image.

pub fn from_miniquad_texture(texture: Texture) -> Texture2D[src]

Creates a Texture2D from a miniquad Texture

pub fn from_rgba8(width: u16, height: u16, bytes: &[u8]) -> Texture2D[src]

Creates a Texture2D from a slice of bytes in an R,G,B,A sequence, with the given width and height.

Example

// Create a 2x2 texture from a byte slice with 4 rgba pixels
let bytes: Vec<u8> = vec![255, 0, 0, 192, 0, 255, 0, 192, 0, 0, 255, 192, 255, 255, 255, 192];
let texture = Texture2D::from_rgba8(2, 2, &bytes);

pub fn update(&self, image: &Image)[src]

Uploads Image data to this texture.

pub fn width(&self) -> f32[src]

Returns the width of this texture.

pub fn height(&self) -> f32[src]

Returns the height of this texture.

pub fn set_filter(&self, filter_mode: FilterMode)[src]

Sets the FilterMode of this texture.

Use Nearest if you need integer-ratio scaling for pixel art, for example.

Example

let texture = Texture2D::empty();
texture.set_filter(FilterMode::Linear);

pub fn raw_miniquad_texture_handle(&self) -> Texture[src]

Returns the handle for this texture.

pub fn grab_screen(&self)[src]

Updates this texture from the screen.

pub fn get_texture_data(&self) -> Image[src]

Returns an Image from the pixel data in this texture.

This operation can be expensive.

pub fn delete(&self)[src]

Unloads texture from GPU memory.

Using a deleted texture could give different results on different platforms and is not recommended.

Trait Implementations

impl Clone for Texture2D[src]

impl Copy for Texture2D[src]

impl Debug for Texture2D[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.