pub struct Texture { /* private fields */ }Expand description
A two dimensional texture stored in video memory.
Textures are copy-on-write, so cloning a texture is cheap
until the clone or the original is modified.
Transparency is supported.
Implementations§
Source§impl Texture
impl Texture
Sourcepub fn new(
ctx: &mut Context,
dimensions: (u32, u32),
) -> Result<Self, NewTextureError>
pub fn new( ctx: &mut Context, dimensions: (u32, u32), ) -> Result<Self, NewTextureError>
Creates a new texture with the given dimensions.
The content of the texture is undefined after its creation.
Sourcepub fn from_image(
ctx: &mut Context,
image: RgbaImage,
) -> Result<Self, NewTextureError>
pub fn from_image( ctx: &mut Context, image: RgbaImage, ) -> Result<Self, NewTextureError>
Creates a new texture from the given image.
Sourcepub fn load<P: AsRef<Path>>(
ctx: &mut Context,
path: P,
) -> Result<Texture, LoadTextureError>
pub fn load<P: AsRef<Path>>( ctx: &mut Context, path: P, ) -> Result<Texture, LoadTextureError>
Loads a texture from an image located at path.
Sourcepub fn get_section(&self, position: (u32, u32), size: (u32, u32)) -> Texture
pub fn get_section(&self, position: (u32, u32), size: (u32, u32)) -> Texture
Returns the part of self specified by position and size as a Texture.
§Panics
This function panics if part of the requested section would be outside of the original texture.
Sourcepub fn dimensions(&self) -> (u32, u32)
pub fn dimensions(&self) -> (u32, u32)
Returns the dimensions of this texture.
Trait Implementations§
Source§impl DrawTarget for Texture
impl DrawTarget for Texture
Source§fn receive_draw(
&mut self,
ctx: &mut Context,
texture: &Texture,
position: (i32, i32),
config: &DrawConfig,
)
fn receive_draw( &mut self, ctx: &mut Context, texture: &Texture, position: (i32, i32), config: &DrawConfig, )
Draws the texture onto self.
This permanently alters self, in case
the original is still required,
consider cloning this Texture first.
It is recommended to call Context::draw instead of
using this method directly.
Source§fn receive_clear_color(
&mut self,
ctx: &mut Context,
color: (f32, f32, f32, f32),
)
fn receive_clear_color( &mut self, ctx: &mut Context, color: (f32, f32, f32, f32), )
self to color.Source§fn receive_clear_depth(&mut self, ctx: &mut Context)
fn receive_clear_depth(&mut self, ctx: &mut Context)
self to 1.0.Source§fn receive_line(
&mut self,
ctx: &mut Context,
from: (i32, i32),
to: (i32, i32),
color: (f32, f32, f32, f32),
)
fn receive_line( &mut self, ctx: &mut Context, from: (i32, i32), to: (i32, i32), color: (f32, f32, f32, f32), )
from to to.