Gamedev Framework (gf)
0.3.0
A C++11 framework for 2D games
|
A texture for colored images. More...
#include <gf/Texture.h>
Public Member Functions | |
Texture () | |
Constructor. More... | |
bool | create (Vector2u size) |
Create the texture. More... | |
bool | loadFromImage (const Image &image) |
Load the texture from an image. More... | |
bool | loadFromFile (const Path &filename) |
Load the texture from a file on disk. More... | |
bool | loadFromStream (InputStream &stream) |
Load the texture from a custom stream. More... | |
bool | loadFromMemory (const uint8_t *data, std::size_t length) |
Load the texture from a file in memory. More... | |
void | update (const Image &image) |
Update the texture from an image. More... | |
Image | copyToImage () const |
Copy the texture pixels to an image. More... | |
Public Member Functions inherited from gf::BareTexture | |
BareTexture (Format format) | |
Constructor. More... | |
~BareTexture () | |
Destructor. More... | |
BareTexture (const BareTexture &)=delete | |
Deleted copy constructor. More... | |
BareTexture & | operator= (const BareTexture &)=delete |
Deleted copy assignment. More... | |
BareTexture (BareTexture &&other) | |
Move constructor. More... | |
BareTexture & | operator= (BareTexture &&other) |
Move assignment. More... | |
Format | getFormat () const |
Get the format of the texture. More... | |
unsigned | getName () const |
Get the internal representation of the texture. More... | |
Vector2u | getSize () const |
Return the size of the texture. More... | |
void | setSmooth (bool smooth=true) |
Enable or disable the smooth filter. More... | |
bool | isSmooth () const noexcept |
Check if the smooth filter is enabled or not. More... | |
void | setRepeated (bool repeated=true) |
Enable or disable repeating. More... | |
bool | isRepeated () const noexcept |
Check if the texture is repeated or not. More... | |
void | update (const uint8_t *data) |
Update the whole texture from an array of pixels. More... | |
void | update (const uint8_t *data, const RectU &rect) |
Update a part of the texture from an array of pixels. More... | |
RectF | computeTextureCoords (const RectU &rect) const |
Compute normalized texture coordinates. More... | |
bool | generateMipmap () |
Generate a mipmap using the current texture data. More... | |
Additional Inherited Members | |
Public Types inherited from gf::BareTexture | |
enum | Format { Format::Color, Format::Alpha } |
Format of the texture. More... | |
Static Public Member Functions inherited from gf::BareTexture | |
static void | bind (const BareTexture *texture) |
Bind a texture for rendering. More... | |
Protected Member Functions inherited from gf::BareTexture | |
bool | create (Vector2u size, const uint8_t *data) |
Create the texture. More... | |
A texture for colored images.
A texture can be loaded from an image, but also directly from a file/memory/stream. The necessary shortcuts are defined so that you don't need an image first for the most common cases. However, if you want to perform some modifications on the pixels before creating the final texture, you can load your file to a gf::Image, do whatever you need with the pixels, and then call Texture::loadFromImage.
Like gf::Image, gf::Texture can handle a unique internal representation of pixels, which is RGBA. This means that a pixel must be composed of 8 bits red, green, blue and alpha channels.
Usage example:
gf::Texture::Texture | ( | ) |
Constructor.
No texture is created.
Image gf::Texture::copyToImage | ( | ) | const |
Copy the texture pixels to an image.
This function performs a slow operation that downloads the texture's pixels from the graphics card and copies them to a new image, potentially applying transformations to pixels if necessary (texture may be padded or flipped).
bool gf::Texture::create | ( | Vector2u | size | ) |
Create the texture.
If this function fails, the texture is left unchanged.
size | Size of the texture |
bool gf::Texture::loadFromFile | ( | const Path & | filename | ) |
Load the texture from a file on disk.
This function is a shortcut for the following code:
If this function fails, the texture is left unchanged.
filename | Path of the image file to load |
bool gf::Texture::loadFromImage | ( | const Image & | image | ) |
Load the texture from an image.
If this function fails, the texture is left unchanged.
image | Image to load into the texture |
bool gf::Texture::loadFromMemory | ( | const uint8_t * | data, |
std::size_t | length | ||
) |
Load the texture from a file in memory.
This function is a shortcut for the following code:
If this function fails, the texture is left unchanged.
data | Pointer to the file data in memory |
length | Length of the data to load, in bytes |
bool gf::Texture::loadFromStream | ( | InputStream & | stream | ) |
Load the texture from a custom stream.
This function is a shortcut for the following code:
If this function fails, the texture is left unchanged.
stream | Source stream to read from |
void gf::Texture::update | ( | const Image & | image | ) |
Update the texture from an image.
Although the source image can be smaller than the texture, this function is usually used for updating the whole texture.
No additional check is performed on the size of the image, passing an image bigger than the texture will lead to an undefined behavior.
This function does nothing if the texture was not previously created.
image | Image to copy to the texture |