Gamedev Framework (gf)
0.3.0
A C++11 framework for 2D games
|
A collection of sub-texture. More...
#include <gf/TextureAtlas.h>
Public Member Functions | |
TextureAtlas () | |
Default constructor. More... | |
bool | loadFromFile (const Path &filename) |
Load an atlas from a XML file. More... | |
void | setTexturePath (const Path &path) |
Set the texture path. More... | |
const Path & | getTexturePath () const |
Get the texture path. More... | |
void | setTexture (const Texture &texture) |
Change the source texture of the atlas. More... | |
const Texture * | getTexture () const |
Get the source texture of the atlas. More... | |
void | unsetTexture () |
Unset the source texture of the atlas. More... | |
void | addSubTexture (std::string name, const RectU &rect) |
Add a sub-texture to the atlas. More... | |
RectU | getSubTexture (const std::string &name) const |
Get the sub-texture rectangle. More... | |
RectF | getTextureRect (const std::string &name) const |
Get the texture rectangle in normalized coordinates. More... | |
A collection of sub-texture.
A texture atlas is a collection of sub-texture that have been packed together in a single texture. The description of the sub-textures is done in a XML file. This description is a name and the texture coordinates in the texture.
Here is an example of a XML file containing an atlas:
gf::TextureAtlas is able to read the XML file and give the coordinates thanks to the name of the sub-texture, either in pixels or in texture normalized coordinates.
|
inline |
Default constructor.
void gf::TextureAtlas::addSubTexture | ( | std::string | name, |
const RectU & | rect | ||
) |
Add a sub-texture to the atlas.
name | The name of the sub-texture |
rect | The rectangle inside the texture |
RectU gf::TextureAtlas::getSubTexture | ( | const std::string & | name | ) | const |
Get the sub-texture rectangle.
name | The name of the sub-texture |
|
inline |
Get the source texture of the atlas.
If the atlas has no source texture, a nullptr
pointer is returned. The returned pointer is const, which means that you can't modify the texture when you retrieve it with this function.
|
inline |
RectF gf::TextureAtlas::getTextureRect | ( | const std::string & | name | ) | const |
Get the texture rectangle in normalized coordinates.
name | The name of the sub-texture |
bool gf::TextureAtlas::loadFromFile | ( | const Path & | filename | ) |
Load an atlas from a XML file.
Load the data about the sub-textures from a XML file.
filename | The filename of the XML file |
|
inline |
Change the source texture of the atlas.
The texture must exist as long as the atlas uses it. Indeed, the atlas doesn't store its own copy of the texture, but rather keeps a pointer to the one that you passed to this function. If the source texture is destroyed and the atlas tries to use it, the behavior is undefined.
texture | New texture |
|
inline |
Set the texture path.
The texture path comes from the XML file when it is loaded.
path | The path to the texture |
|
inline |
Unset the source texture of the atlas.
After a call to this function, the atlas has no source texture.