Public Types | Public Member Functions | Static Public Member Functions | List of all members
ime::Texture Class Reference

Image living on the graphics card that can be used for drawing. More...

#include <Texture.h>

Public Types

using Ptr = std::shared_ptr< Texture >
 shared texture pointer More...
 

Public Member Functions

 Texture ()
 Constructor. More...
 
 Texture (const std::string &filename, const UIntRect &area=UIntRect())
 Construct the texture. More...
 
 Texture (const Texture &)
 Copy constructor. More...
 
Textureoperator= (const Texture &)
 Copy assignment operator. More...
 
 Texture (Texture &&) noexcept
 Move constructor. More...
 
Textureoperator= (Texture &&) noexcept
 Move assignment operator. More...
 
bool create (unsigned int width, unsigned int height)
 Create an empty texture. More...
 
bool create (const Vector2u &size)
 Create an empty texture. More...
 
void loadFromFile (const std::string &filename, const UIntRect &area=UIntRect())
 Load the texture from an image on the disk. More...
 
bool saveToFile (const std::string &filename)
 Save the texture to file on disk. More...
 
Vector2u getSize () const
 Get the size of the texture. More...
 
void setSmooth (bool smooth)
 Enable or disable the smooth filter. More...
 
bool isSmooth () const
 Check whether the smooth filter is enabled or not. More...
 
void setRepeated (bool repeated)
 Enable or disable repeating. More...
 
bool isRepeated () const
 Check whether the texture is repeated or not. More...
 
const std::string & getFilename () const
 Get the filename of the image the texture was loaded from. More...
 
void update (const priv::RenderTarget &renderTarget, unsigned int x, unsigned int y)
 
bool operator!= (const Texture &other) const
 Check if this texture is not the same as another texture. More...
 
const sf::Texture & getInternalTexture () const
 
 ~Texture ()
 Destructor. More...
 

Static Public Member Functions

static unsigned int getMaximumSize ()
 Get the maximum texture size allowed. More...
 

Detailed Description

Image living on the graphics card that can be used for drawing.

Definition at line 47 of file Texture.h.

Member Typedef Documentation

◆ Ptr

using ime::Texture::Ptr = std::shared_ptr<Texture>

shared texture pointer

Definition at line 49 of file Texture.h.

Constructor & Destructor Documentation

◆ Texture() [1/4]

ime::Texture::Texture ( )

Constructor.

Creates an empty texture of size {0, 0}

See also
loadFromFile

◆ Texture() [2/4]

ime::Texture::Texture ( const std::string &  filename,
const UIntRect area = UIntRect() 
)
explicit

Construct the texture.

Parameters
filenameFilename of the image file to load
areaArea of the image to load
Exceptions
FileNotFoundExceptionif the filename cannot be found on the disk

The area can be used to construct the texture from a sub-rectangle of the whole image. To construct the texture from the whole image (default), leave the area argument unspecified. If the area rectangle crosses the bounds of the image, it is adjusted to fit the image size

◆ Texture() [3/4]

ime::Texture::Texture ( const Texture )

Copy constructor.

◆ Texture() [4/4]

ime::Texture::Texture ( Texture &&  )
noexcept

Move constructor.

◆ ~Texture()

ime::Texture::~Texture ( )

Destructor.

Member Function Documentation

◆ create() [1/2]

bool ime::Texture::create ( const Vector2u size)

Create an empty texture.

Parameters
sizeThe size of the texture
Returns
True if the texture was created successfully, or false if the creation failed

You can use this function if you want the texture to have a size but intend to load the image file at a later time.

This function fails if the specified size is invalid. The size must be greater than zero but less than the maximum allowed size of the texture (see getMaximumSize()). If this function fails, the texture is left unchanged

See also
loadFromFile

◆ create() [2/2]

bool ime::Texture::create ( unsigned int  width,
unsigned int  height 
)

Create an empty texture.

Parameters
widthThe width of the texture
heightThe height of the texture
Returns
True if the texture was created successfully, or false if the creation failed

You can use this function if you want the texture to have a size but intend to load the image file at a later time.

This function fails if the specified size is invalid. The size must be greater than zero but less than the maximum allowed size of the texture (see getMaximumSize()). If this function fails, the texture is left unchanged

See also
loadFromFile

◆ getFilename()

const std::string & ime::Texture::getFilename ( ) const

Get the filename of the image the texture was loaded from.

Returns
The filename of the image the texture was created from

◆ getMaximumSize()

static unsigned int ime::Texture::getMaximumSize ( )
static

Get the maximum texture size allowed.

Returns
The maximum size allowed for textures, in pixels

This maximum size is defined by the graphics driver. You can expect a value of 512 pixels for low-end graphics card, and up to 8192 pixels or more for newer hardware.

◆ getSize()

Vector2u ime::Texture::getSize ( ) const

Get the size of the texture.

Returns
The size of the texture in pixels

◆ isRepeated()

bool ime::Texture::isRepeated ( ) const

Check whether the texture is repeated or not.

Returns
True if repeat mode is enabled, false if it is disabled
See also
setRepeated

◆ isSmooth()

bool ime::Texture::isSmooth ( ) const

Check whether the smooth filter is enabled or not.

Returns
True if smoothing is enabled, false if it is disabled
See also
setSmooth

◆ loadFromFile()

void ime::Texture::loadFromFile ( const std::string &  filename,
const UIntRect area = UIntRect() 
)

Load the texture from an image on the disk.

Parameters
filenameFilename of the image file to load
areaArea of the image to load
Exceptions
FileNotFoundExceptionif the filename cannot be found on the disk

The area can be used to construct the texture from a sub-rectangle of the whole image. To construct the texture from the whole image (default), leave the area argument unspecified. If the area rectangle crosses the bounds of the image, it is adjusted to fit the image size

◆ operator!=()

bool ime::Texture::operator!= ( const Texture other) const

Check if this texture is not the same as another texture.

Parameters
otherThe texture to compare against this texture
Returns
True if the two textures are not the same, otherwise false

◆ operator=() [1/2]

Texture & ime::Texture::operator= ( const Texture )

Copy assignment operator.

◆ operator=() [2/2]

Texture & ime::Texture::operator= ( Texture &&  )
noexcept

Move assignment operator.

◆ saveToFile()

bool ime::Texture::saveToFile ( const std::string &  filename)

Save the texture to file on disk.

Parameters
filenamePath of the file to save
Returns
True if the texture was saved successfully, or false if the texture is empty

The format of the image is automatically deduced from the file extension. The supported image formats are bmp, png, tga and jpg. The destination file is overwritten if it already exists

Note
This function performs a slow operation

◆ setRepeated()

void ime::Texture::setRepeated ( bool  repeated)

Enable or disable repeating.

Parameters
repeatedTrue to repeat the texture, false to disable repeating

Repeating is involved when using texture coordinates outside the texture rectangle [0, 0, width, height]. In this case, if repeat mode is enabled, the whole texture will be repeated as many times as needed to reach the coordinate (for example, if the X texture coordinate is 3 * width, the texture will be repeated 3 times). If repeat mode is disabled, the "extra space" will instead be filled with border pixels.

Repeating is disabled by default.

Warning
On very old graphics cards, white pixels may appear when the texture is repeated. With such cards, repeat mode can be used reliably only if the texture has power-of-two dimensions (such as 256x128).

◆ setSmooth()

void ime::Texture::setSmooth ( bool  smooth)

Enable or disable the smooth filter.

Parameters
smoothTrue to enable smoothing or false to disable it

When the filter is activated, the texture appears smoother so that pixels are less noticeable. However if you want the texture to look exactly the same as its source file, you should leave it disabled

The smooth filter is disabled by default


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