Struct cgl_rs::graphics::Tilemap

source ·
#[repr(C)]
pub struct Tilemap { /* private fields */ }
Expand description

The Tilemap Object

Implementations§

source§

impl Tilemap

source

pub fn new( tile_count_x: u32, tile_count_y: u32, tile_size_x: u32, tile_size_y: u32, ssbo_binding: u32 ) -> Result<Tilemap, &'static str>

Creates a new Tilemap object with the specified dimensions and SSBO binding.

Arguments
  • tile_count_x - The number of tiles in the x direction.
  • tile_count_y - The number of tiles in the y direction.
  • tile_size_x - The width of each tile in pixels.
  • tile_size_y - The height of each tile in pixels.
  • ssbo_binding - The SSBO binding index to use for the tilemap.
Returns

A Result containing the new Tilemap object if successful, or an error message if creation failed.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("CGL Window", 800, 600).unwrap();
cgl_rs::graphics::init();
{
    let tilemap = cgl_rs::graphics::Tilemap::new(10, 10, 32, 32, 0).unwrap();
    // Do stuff with tilemap
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn set_auto_upload(&self, value: bool)

Sets whether the tilemap should automatically upload changes to the GPU.

Arguments
  • value - A boolean value indicating whether the tilemap should automatically upload changes to the GPU.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("CGL Window", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let tilemap = cgl_rs::graphics::Tilemap::new(10, 10, 32, 32, 0).unwrap();
   tilemap.set_auto_upload(false);
   // Do stuff with tilemap
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn get_auto_upload(&self) -> bool

Returns whether the tilemap is set to automatically upload changes to the GPU.

Returns

A boolean value indicating whether the tilemap is set to automatically upload changes to the GPU.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("CGL Window", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let tilemap = cgl_rs::graphics::Tilemap::new(10, 10, 32, 32, 0).unwrap();
   let auto_upload = tilemap.get_auto_upload();
   // Do stuff with tilemap
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn upload(&self)

Uploads any changes made to the tilemap to the GPU. This can be slow, so it is recommended to set auto upload to false and manually call this function when needed for large tilemaps.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("CGL Window", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let tilemap = cgl_rs::graphics::Tilemap::new(10, 10, 32, 32, 0).unwrap();
   tilemap.set_auto_upload(false);
   tilemap.set_tile_color(0, 0, 1.0, 0.0, 0.0, 1.0);
   tilemap.upload();
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn set_tile_color( &self, tile_x: u32, tile_y: u32, r: f32, g: f32, b: f32, _a: f32 )

Sets the color of a specific tile in the tilemap.

Arguments
  • tile_x - The x-coordinate of the tile to set the color of.
  • tile_y - The y-coordinate of the tile to set the color of.
  • r - The red component of the color to set.
  • g - The green component of the color to set.
  • b - The blue component of the color to set.
  • _a - The alpha component of the color to set. This is currently unused.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("CGL Window", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let tilemap = cgl_rs::graphics::Tilemap::new(10, 10, 32, 32, 0).unwrap();
   tilemap.set_tile_color(0, 0, 1.0, 0.0, 0.0, 1.0);
   // Do stuff with tilemap
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn set_tile_texture_from_array( &self, tile_x: u32, tile_y: u32, texture_index: u32 )

Sets the texture of a specific tile in the tilemap using an array of textures.

Arguments
  • tile_x - The x-coordinate of the tile to set the texture of.
  • tile_y - The y-coordinate of the tile to set the texture of.
  • texture_index - The index of the texture to set.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("CGL Window", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let tilemap = cgl_rs::graphics::Tilemap::new(10, 10, 32, 32, 0).unwrap();
   tilemap.set_tile_texture_from_array(0, 0, 1);
   // Do stuff with tilemap
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn set_tile_texture_from_tileset( &self, tile_x: u32, tile_y: u32, texture_x_min: f32, texture_y_min: f32, texture_x_max: f32, texture_y_max: f32 )

Sets the texture of a specific tile in the tilemap using a tileset.

Arguments
  • tile_x - The x-coordinate of the tile to set the texture of.
  • tile_y - The y-coordinate of the tile to set the texture of.
  • texture_x_min - The minimum x-coordinate of the texture in the tileset.
  • texture_y_min - The minimum y-coordinate of the texture in the tileset.
  • texture_x_max - The maximum x-coordinate of the texture in the tileset.
  • texture_y_max - The maximum y-coordinate of the texture in the tileset.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("CGL Window", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let tilemap = cgl_rs::graphics::Tilemap::new(10, 10, 32, 32, 0).unwrap();
   tilemap.set_tile_texture_from_tileset(0, 0, 0.0, 0.0, 1.0, 1.0);
   // Do stuff with tilemap
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn set_all_tile_color(&self, r: f32, g: f32, b: f32, _a: f32)

Sets the color of all tiles in the tilemap.

Arguments
  • r - The red component of the color.
  • g - The green component of the color.
  • b - The blue component of the color.
  • _a - The alpha component of the color (currently unused).
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("CGL Window", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let tilemap = cgl_rs::graphics::Tilemap::new(10, 10, 32, 32, 0).unwrap();
   tilemap.set_all_tile_color(1.0, 0.0, 0.0, 1.0);
   // Do stuff with tilemap
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn set_all_tile_texture_from_array(&self, texture_index: u32)

Sets the texture of all tiles in the tilemap using an array of texture indices.

Arguments
  • texture_index - The index of the texture to set for all tiles.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("CGL Window", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let tilemap = cgl_rs::graphics::Tilemap::new(10, 10, 32, 32, 0).unwrap();
   tilemap.set_all_tile_texture_from_array(0);
   // Do stuff with tilemap
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn set_all_tile_texture_from_tileset( &self, texture_x_min: f32, texture_y_min: f32, texture_x_max: f32, texture_y_max: f32 )

Sets the texture of all tiles in the tilemap using a tileset.

Arguments
  • texture_x_min - The minimum x-coordinate of the texture in the tileset.
  • texture_y_min - The minimum y-coordinate of the texture in the tileset.
  • texture_x_max - The maximum x-coordinate of the texture in the tileset.
  • texture_y_max - The maximum y-coordinate of the texture in the tileset.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("CGL Window", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let tilemap = cgl_rs::graphics::Tilemap::new(10, 10, 32, 32, 0).unwrap();
   tilemap.set_all_tile_texture_from_tileset(0.0, 0.0, 1.0, 1.0);
   // Do stuff with tilemap
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn clear_tile(&self, tile_x: u32, tile_y: u32)

Clears the tile at the specified position.

Arguments
  • tile_x - The x-coordinate of the tile to clear.
  • tile_y - The y-coordinate of the tile to clear.
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("CGL Window", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let tilemap = cgl_rs::graphics::Tilemap::new(10, 10, 32, 32, 0).unwrap();
   tilemap.clear_tile(0, 0);
   // Do stuff with tilemap
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn clear_all_tile(&self)

Clears all tiles in the tilemap.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("CGL Window", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let tilemap = cgl_rs::graphics::Tilemap::new(10, 10, 32, 32, 0).unwrap();
   tilemap.clear_all_tile();
   // Do stuff with tilemap
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn render( &self, scale_x: f32, scale_y: f32, offset_x: f32, offset_y: f32, texture: Option<&mut Texture> )

Renders the tilemap to the screen.

Arguments
  • scale_x - The x-axis scale factor.
  • scale_y - The y-axis scale factor.
  • offset_x - The x-axis offset.
  • offset_y - The y-axis offset.
  • texture - The texture to use for rendering (optional).
Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("CGL Window", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let mut tilemap = cgl_rs::graphics::Tilemap::new(10, 10, 32, 32, 0).unwrap();
   let mut texture = cgl_rs::graphics::Texture::dummy().unwrap();
   tilemap.set_all_tile_texture_from_tileset(0.0, 0.0, 1.0, 1.0);
   tilemap.render(1.0, 1.0, 0.0, 0.0, Some(&mut texture));
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();
source

pub fn destroy(&mut self)

Destroys the tilemap object.

Example
cgl_rs::init();
let mut window = cgl_rs::Window::new("Hello, World!", 800, 600).unwrap();
cgl_rs::graphics::init();
{
   let mut tilemap = cgl_rs::graphics::Tilemap::new(10, 10, 32, 32, 0).unwrap();
   tilemap.destroy(); // Or, just let the tilemap go out of scope.
}
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();

Trait Implementations§

source§

impl Clone for Tilemap

source§

fn clone(&self) -> Self

Returns a copy 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 Drop for Tilemap

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.