![]() |
Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
|
A texture for colored images. More...
#include <gf/Texture.h>
Public Member Functions | |
Texture () | |
Constructor. More... | |
Texture (Vector2i size) | |
Create the texture. More... | |
Texture (const Image &image) | |
Load the texture from an image. More... | |
Texture (const Image &image, const RectI &area) | |
Load the texture from a sub-area of an image. More... | |
Texture (const Path &filename) | |
Load the texture from a file on disk. More... | |
Texture (const Path &filename, const RectI &area) | |
Load the texture from a sub-area of a file on disk. More... | |
Texture (InputStream &stream) | |
Load the texture from a custom stream. More... | |
Texture (InputStream &stream, const RectI &area) | |
Load the texture from a sub-area of a custom stream. More... | |
Texture (Span< const uint8_t > content) | |
Load the texture from a file in memory. More... | |
Texture (Span< const uint8_t > content, const RectI &area) | |
Load the texture from a sub-area of 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... | |
![]() | |
BareTexture (Format format) | |
Constructor. More... | |
BareTexture (Format format, Vector2i size, const uint8_t *data) | |
Create the texture. More... | |
Format | getFormat () const |
Get the format of the texture. More... | |
unsigned | getName () const |
Get the internal representation of the texture. More... | |
Vector2i | 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 RectI &rect) |
Update a part of the texture from an array of pixels. More... | |
void | resize (Vector2i size, const uint8_t *data=nullptr) |
Resize a texture. More... | |
RectF | computeTextureCoords (const RectI &rect) const |
Compute normalized texture coordinates. More... | |
bool | generateMipmap () |
Generate a mipmap using the current texture data. More... | |
Additional Inherited Members | |
![]() | |
enum class | Format { Color , Alpha } |
Format of the texture. More... | |
![]() | |
static void | bind (const BareTexture *texture) |
Bind a texture for rendering. 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 the appropriate constructor.
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.
gf::Texture::Texture | ( | Vector2i | size | ) |
Create the texture.
size | Size of the texture |
gf::Texture::Texture | ( | const Image & | image | ) |
Load the texture from an image.
image | Image to load into the texture |
Load the texture from a sub-area of an image.
image | Image to load into the texture |
area | Sub-area of the image |
gf::Texture::Texture | ( | const Path & | filename | ) |
Load the texture from a file on disk.
filename | Path of the image file to load |
Load the texture from a sub-area of a file on disk.
filename | Path of the image file to load |
area | Sub-area of the image |
gf::Texture::Texture | ( | InputStream & | stream | ) |
Load the texture from a custom stream.
stream | Source stream to read from |
gf::Texture::Texture | ( | InputStream & | stream, |
const RectI & | area | ||
) |
Load the texture from a sub-area of a custom stream.
stream | Source stream to read from |
area | Sub-area of the image |
gf::Texture::Texture | ( | Span< const uint8_t > | content | ) |
Load the texture from a file in memory.
content | Content of the file data in memory |
Load the texture from a sub-area of a file in memory.
content | Content of the file data in memory |
area | Sub-area of the image |
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).
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 |