Struct cgl_rs::graphics::Texture

source ·
pub struct Texture { /* private fields */ }
Expand description

The texture object

Implementations§

source§

impl Texture

source

pub fn blank_i( width: i32, height: i32, format: u32, internal_format: u32, data_type: u32 ) -> Result<Texture, &'static str>

Creates a new blank texture with the specified dimensions and format.

Arguments
  • width - The width of the texture in pixels.
  • height - The height of the texture in pixels.
  • format - The format of the texture data.
  • internal_format - The internal format of the texture data.
  • data_type - The data type of the texture data.
Returns

A Result containing the newly created Texture if successful, or an error message if creation failed.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let texture = cgl_rs::graphics::Texture::blank_i(256, 256, cgl_rs::graphics::TextureFormat::RGBA as u32, cgl_rs::graphics::TextureInternalFormat::RGBA8UI as u32, cgl_rs::graphics::TextureDataType::UNSIGNED_BYTE as u32).unwrap();
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn blank( width: i32, height: i32, format: TextureFormat, internal_format: TextureInternalFormat, data_type: TextureDataType ) -> Result<Texture, &'static str>

Creates a new blank texture with the specified dimensions and format.

Arguments
  • width - The width of the texture in pixels.
  • height - The height of the texture in pixels.
  • format - The format of the texture data.
  • internal_format - The internal format of the texture data.
  • data_type - The data type of the texture data.
Returns

A Result containing the newly created Texture if successful, or an error message if creation failed.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let texture = cgl_rs::graphics::Texture::blank(256, 256, cgl_rs::graphics::TextureFormat::RGBA, cgl_rs::graphics::TextureInternalFormat::RGBA8UI, cgl_rs::graphics::TextureDataType::UNSIGNED_BYTE).unwrap();
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn dummy() -> Result<Texture, &'static str>

Creates a new dummy texture with a single pixel.

Returns

A Result containing the newly created Texture if successful, or an error message if creation failed.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let texture = cgl_rs::graphics::Texture::dummy().unwrap();
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn dummy2(width: i32, height: i32) -> Result<Texture, &'static str>

Creates a new dummy texture with the specified dimensions.

Arguments
  • width - The width of the texture in pixels.
  • height - The height of the texture in pixels.
Returns

A Result containing the newly created Texture if successful, or an error message if creation failed.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let texture = cgl_rs::graphics::Texture::dummy2(256, 256).unwrap();
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn array_i( width: i32, height: i32, depth: i32, format: u32, internal_format: u32, data_type: u32 ) -> Result<Texture, &'static str>

Creates a new texture array with the specified dimensions and format.

Arguments
  • width - The width of the texture in pixels.
  • height - The height of the texture in pixels.
  • depth - The depth of the texture array.
  • format - The format of the texture data.
  • internal_format - The internal format of the texture data.
  • data_type - The data type of the texture data.
Returns

A Result containing the newly created Texture if successful, or an error message if creation failed.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let texture = cgl_rs::graphics::Texture::array_i(256, 256, 6, cgl_rs::graphics::TextureFormat::RGBA as u32, cgl_rs::graphics::TextureInternalFormat::RGBA8UI as u32, cgl_rs::graphics::TextureDataType::UNSIGNED_BYTE as u32).unwrap();
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn array( width: i32, height: i32, depth: i32, format: TextureFormat, internal_format: TextureInternalFormat, data_type: TextureDataType ) -> Result<Texture, &'static str>

Arguments
  • width - The width of the texture in pixels.
  • height - The height of the texture in pixels.
  • depth - The depth of the texture array.
  • format - The format of the texture data.
  • internal_format - The internal format of the texture data.
  • data_type - The data type of the texture data.
Returns

A Result containing the newly created Texture if successful, or an error message if creation failed.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let texture = cgl_rs::graphics::Texture::array(256, 256, 6, cgl_rs::graphics::TextureFormat::RGBA, cgl_rs::graphics::TextureInternalFormat::RGBA8UI, cgl_rs::graphics::TextureDataType::UNSIGNED_BYTE).unwrap();
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn cubemap() -> Result<Texture, &'static str>

Creates a new cubemap texture.

Returns

A Result containing the newly created Texture if successful, or an error message if creation failed.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let texture = cgl_rs::graphics::Texture::cubemap().unwrap();
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn array_set_layer_data(&self, layer: i32, data: &[u8])

Sets the data for a single layer of a texture array.

Arguments
  • layer - The index of the layer to set the data for.
  • data - A slice containing the data to set for the layer.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let mut texture = cgl_rs::graphics::Texture::array(256, 256, 6, cgl_rs::graphics::TextureFormat::RGBA, cgl_rs::graphics::TextureInternalFormat::RGBA8UI, cgl_rs::graphics::TextureDataType::UNSIGNED_BYTE).unwrap();
    let data = vec![0u8; 256 * 256 * 4];
    texture.array_set_layer_data(0, &data);
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn bind(&self, unit: u32)

Binds the texture to a texture unit.

Arguments
  • unit - The texture unit to bind the texture to.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let texture = cgl_rs::graphics::Texture::dummy().unwrap();
    texture.bind(0);
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn set_data(&self, data: *const u8)

Sets the data for the texture.

Arguments
  • data - A slice containing the data to set for the texture.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let mut texture = cgl_rs::graphics::Texture::dummy2(256, 256).unwrap();
    let data = vec![0u8; 256 * 256 * 4];
    texture.set_data(data.as_ptr());
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn set_sub_data( &self, x: usize, y: usize, width: usize, height: usize, data: *const u8 )

Sets a rectangular subregion of the texture with new data.

Arguments
  • x - The x-coordinate of the lower left corner of the subregion.
  • y - The y-coordinate of the lower left corner of the subregion.
  • width - The width of the subregion.
  • height - The height of the subregion.
  • data - A slice containing the new data to set for the subregion.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let mut texture = cgl_rs::graphics::Texture::dummy2(256, 256).unwrap();
    let data = vec![255u8; 100 * 100 * 4];
    texture.set_sub_data(0, 0, 100, 100, data.as_ptr());
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn get_internal_gl_handle(&self) -> u32

Returns the internal OpenGL handle of the texture.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let texture = cgl_rs::graphics::Texture::dummy().unwrap();
    let handle = texture.get_internal_gl_handle();
    println!("Internal OpenGL handle: {}", handle);
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn set_scaling_method_i(&self, method: i32)

Sets the scaling method of the texture.

Arguments
  • method - The scaling method to use for the texture.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let mut texture = cgl_rs::graphics::Texture::dummy2(256, 256).unwrap();
    texture.set_scaling_method_i(1);
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn set_scaling_method(&self, method: TextureScalingMode)

Arguments
  • method - The scaling method to use for the texture.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let mut texture = cgl_rs::graphics::Texture::dummy2(256, 256).unwrap();
    texture.set_scaling_method(cgl_rs::graphics::TextureScalingMode::LINEAR);
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn set_wrapping_method_i(&self, method: i32)

Sets the wrapping method of the texture.

Arguments
  • method - The wrapping method to use for the texture.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let mut texture = cgl_rs::graphics::Texture::dummy2(256, 256).unwrap();
   texture.set_wrapping_method_i(1);
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn set_wrapping_method(&self, method: TextureWrappingMode)

Sets the wrapping method of the texture.

Arguments
  • method - The wrapping method to use for the texture.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let mut texture = cgl_rs::graphics::Texture::dummy2(256, 256).unwrap();
   texture.set_wrapping_method(cgl_rs::graphics::TextureWrappingMode::CLAMP_TO_EDGE);
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn destroy(&mut self)

Destroys the texture and frees its resources. If the texture has already been destroyed, this method does nothing.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let mut texture = cgl_rs::graphics::Texture::dummy().unwrap();
    texture.destroy(); // optional
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();

Trait Implementations§

source§

impl Clone for Texture

source§

fn clone(&self) -> Self

Clones the texture.

NOTE: The new instance will have the same handle, has_been_destroyed flag. This means that the new instance will not be able to receive events nor will the internal window handle be destroyed when the new instance is dropped. The internal window handle will be destroyed when the original instance is dropped.

Returns

A new instance of Texture with the same handle as the original texture.

1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Drop for Texture

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

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 Twhere 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 Twhere 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.