Vesper 0.5.1
Vesper is short form for the Latin word for "Bat", as Vesper is designed to be small, lightweight, and easily handle things like particles and flocking behaviors in accordance with the nature of bats. \n It is meant to be a particle simulation, VFX editor, and CAN be used secondarily as a small game engine.
GitHub | Vesper Updates | Creator
Loading...
Searching...
No Matches
Vesper::SubTexture2D Class Reference

Represents a sub-region of a 2D texture, useful for sprite sheets. More...

#include <SubTexture2D.h>

Public Member Functions

 SubTexture2D (const Ref< Texture2D > &texture, const glm::vec2 &min, const glm::vec2 &max)
 Constructs a SubTexture2D from the given texture and texture coordinates.
const Ref< Texture2DGetTexture ()
 Returns the underlying texture of the sub-texture.
glm::vec2 * GetTexCoords ()
 Returns the texture coordinates of the sub-texture.

Static Public Member Functions

static Ref< SubTexture2DCreateFromCoords (const Ref< Texture2D > &texture, const glm::vec2 &coords, const glm::vec2 &cellSize, const glm::vec2 &spriteSize={1, 1})
 Creates a SubTexture2D from a grid of cells within the given texture.

Private Attributes

Ref< Texture2Dm_Texture
 The underlying texture of the sub-texture.
glm::vec2 m_TexCoords [4]
 The texture coordinates of the sub-texture.

Detailed Description

Represents a sub-region of a 2D texture, useful for sprite sheets.

Constructor & Destructor Documentation

◆ SubTexture2D()

Vesper::SubTexture2D::SubTexture2D ( const Ref< Texture2D > & texture,
const glm::vec2 & min,
const glm::vec2 & max )

Constructs a SubTexture2D from the given texture and texture coordinates.

Parameters
textureThe texture from which the sub-texture is derived.
minThe minimum texture coordinates (bottom-left).
maxThe maximum texture coordinates (top-right).
9 : m_Texture(texture)
10 {
11 m_TexCoords[0] = { min.x, min.y };
12 m_TexCoords[1] = { max.x, min.y };
13 m_TexCoords[2] = { max.x, max.y };
14 m_TexCoords[3] = { min.x, max.y };
15 }
Ref< Texture2D > m_Texture
The underlying texture of the sub-texture.
Definition SubTexture2D.h:36
glm::vec2 m_TexCoords[4]
The texture coordinates of the sub-texture.
Definition SubTexture2D.h:38

References SubTexture2D().

Referenced by SubTexture2D().

Member Function Documentation

◆ CreateFromCoords()

Ref< SubTexture2D > Vesper::SubTexture2D::CreateFromCoords ( const Ref< Texture2D > & texture,
const glm::vec2 & coords,
const glm::vec2 & cellSize,
const glm::vec2 & spriteSize = {1, 1} )
static

Creates a SubTexture2D from a grid of cells within the given texture.

Parameters
textureThe texture from which the sub-texture is derived.
coordsThe coordinates of the cell in the grid.
cellSizeThe size of each cell in the grid.
spriteSizeThe size of the sprite in cells (default is 1x1).
18 {
19 glm::vec2 min = { (coords.x * cellSize.x) / texture->GetWidth(), (coords.y * cellSize.y) / texture->GetHeight() };
20 glm::vec2 max = { ((coords.x + spriteSize.x) * cellSize.x) / texture->GetWidth(), ((coords.y + spriteSize.y) * cellSize.y) / texture->GetHeight() };
21
22 return CreateRef<SubTexture2D>(texture, min, max);
23 }
constexpr Ref< T > CreateRef(Args &&... args)
Creates a Ref (shared_ptr) for the given type and constructor arguments.
Definition Defines_Macros.h:72

◆ GetTexCoords()

glm::vec2 * Vesper::SubTexture2D::GetTexCoords ( )
inline

Returns the texture coordinates of the sub-texture.

25{ return m_TexCoords; }

◆ GetTexture()

const Ref< Texture2D > Vesper::SubTexture2D::GetTexture ( )
inline

Returns the underlying texture of the sub-texture.

23{ return m_Texture; }

Member Data Documentation

◆ m_TexCoords

glm::vec2 Vesper::SubTexture2D::m_TexCoords[4]
private

The texture coordinates of the sub-texture.

◆ m_Texture

Ref<Texture2D> Vesper::SubTexture2D::m_Texture
private

The underlying texture of the sub-texture.


The documentation for this class was generated from the following files: