Struct sdl2::surface::Surface [−][src]
pub struct Surface<'a> { /* fields omitted */ }
Expand description
Holds a Rc<SurfaceContext>
.
Note: If a Surface
goes out of scope but it cloned its context,
then the SDL_Surface
will not be free’d until there are no more references to the SurfaceContext
.
Implementations
Creates a new surface using a pixel format.
Example
use sdl2::pixels::PixelFormatEnum;
use sdl2::surface::Surface;
let surface = Surface::new(512, 512, PixelFormatEnum::RGB24).unwrap();
pub fn from_pixelmasks(
width: u32,
height: u32,
masks: PixelMasks
) -> Result<Surface<'static>, String>
pub fn from_pixelmasks(
width: u32,
height: u32,
masks: PixelMasks
) -> Result<Surface<'static>, String>
Creates a new surface using pixel masks.
Example
use sdl2::pixels::PixelFormatEnum;
use sdl2::surface::Surface;
let masks = PixelFormatEnum::RGB24.into_masks().unwrap();
let surface = Surface::from_pixelmasks(512, 512, masks).unwrap();
Creates a new surface from an existing buffer, using a pixel format.
Creates a new surface from an existing buffer, using pixel masks.
pub fn as_texture<'b, T>(
&self,
texture_creator: &'b TextureCreator<T>
) -> Result<Texture<'b>, TextureValueError>
pub fn as_texture<'b, T>(
&self,
texture_creator: &'b TextureCreator<T>
) -> Result<Texture<'b>, TextureValueError>
A convenience function for TextureCreator::create_texture_from_surface
.
use sdl2::pixels::PixelFormatEnum;
use sdl2::surface::Surface;
use sdl2::render::{Canvas, Texture};
use sdl2::video::Window;
// We init systems.
let sdl_context = sdl2::init().expect("failed to init SDL");
let video_subsystem = sdl_context.video().expect("failed to get video context");
// We create a window.
let window = video_subsystem.window("sdl2 demo", 800, 600)
.build()
.expect("failed to build window");
// We get the canvas from which we can get the `TextureCreator`.
let mut canvas: Canvas<Window> = window.into_canvas()
.build()
.expect("failed to build window's canvas");
let texture_creator = canvas.texture_creator();
let surface = Surface::new(512, 512, PixelFormatEnum::RGB24).unwrap();
let texture = surface.as_texture(&texture_creator).unwrap();
Creates a Software Canvas to allow rendering in the Surface itself. This Canvas
will
never be accelerated materially, so there is no performance change between Surface
and
Canvas
coming from a Surface
.
The only change is this case is that Canvas
has a
better API to draw stuff in the Surface
in that case, but don’t expect any performance
changes, there will be none.
Methods from Deref<Target = SurfaceRef>
Locks a surface so that the pixels can be directly accessed safely.
Locks a surface so that the pixels can be directly accessed safely.
Returns the Surface’s pixel buffer if the Surface doesn’t require locking (e.g. it’s a software surface).
Returns the Surface’s pixel buffer if the Surface doesn’t require locking (e.g. it’s a software surface).
Returns true if the Surface needs to be locked before accessing the Surface pixels.
The function will fail if the surface doesn’t have color key enabled.
pub fn fill_rect<R>(&mut self, rect: R, color: Color) -> Result<(), String> where
R: Into<Option<Rect>>,
The function will fail if the blend mode is not supported by SDL.
Sets the clip rectangle for the surface.
If the rectangle is None
, clipping will be disabled.
Gets the clip rectangle for the surface.
Returns None
if clipping is disabled.
Copies the surface into a new one that is optimized for blitting to a surface of a specified pixel format.
Copies the surface into a new one of a specified pixel format.
Performs surface blitting (surface copying).
Returns the final blit rectangle, if a dst_rect
was provided.
Performs low-level surface blitting.
Unless you know what you’re doing, use blit()
instead, which will clip the input rectangles.
This function could crash if the rectangles aren’t pre-clipped to the surface, and is therefore unsafe.
Performs scaled surface bliting (surface copying).
Returns the final blit rectangle, if a dst_rect
was provided.
Performs low-level scaled surface blitting.
Unless you know what you’re doing, use blit_scaled()
instead, which will clip the input rectangles.
This function could crash if the rectangles aren’t pre-clipped to the surface, and is therefore unsafe.
Trait Implementations
Performs the conversion.
Performs the conversion.
type Target = SurfaceRef
type Target = SurfaceRef
The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.
type Context = SurfaceContext<'s>
Rotates and zooms a surface and optional anti-aliasing.
Rotates and zooms a surface with different horizontal and vertical scaling factors and optional anti-aliasing.
Zoom a surface by independent horizontal and vertical factors with optional smoothing.
Shrink a surface by an integer ratio using averaging.