mElite  1.0
An Elite clone based on TextElite by Jan-Philipp Kappmeier and Melanie Schmidt.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
List of all members
Textures Class Reference

Implements a texture manager that loads files and sets up OpenGL textures. More...

#include <Textures.h>

Construction

The constructors and destructor for a singleton object. The function Textures::getTextures() is used to access the class.

static TexturesgetTextures (void)
 Public access to singleton object.
 
 ~Textures ()
 Destructor.
 

Textureloading

These functions are used to load and unload textures from the memory. To guarantee fast loading of many textures, the function Textures::reserve() should be used to reserve memory. The mode in which the textures are loaded can also be changed.

void changeColors (bool value)
 Set's conversion between RGB and BGR on and off.
 
void loadTexture (unsigned int texture, std::string filename)
 Loads a texture from a file into a texture slot.
 
void loadTexture (unsigned int texture, TextureLoader *loader)
 Loads a texture from memory into a texture slot.
 
void reserve (unsigned int count)
 Reserves space for textures in the vector.
 
void freeTexture (unsigned int texture)
 Frees texture memory.
 

Additional functionalities

These functions provide some additional functionalities. The Textures::bindTexture() function allows it easyly to bind a loaded texture as GL_TEXTURE_2D.

void bindTexture (unsigned int texture)
 Binds a texture.
 

Detailed Description

Implements a texture manager that loads files and sets up OpenGL textures.

Allows automatically to load and unload textures into OpenGL. It hides all the stuff needed by OpenGL such as the TexIDs. All textures can be accessed by a simple unsingned integer value. Internally the OpenGL TexIDs are assigned to one of these values. The assignment is stored in a vector. If a texture should be loaded with an id that has already been used, the old texture is unloaded. The textures are actual loaded by an abstract TextureLoader object. Depending from the format of the texture an instance of inherited loader classes is created and the appropriate Textures::load() function is called via the polymorphism.

Also this class gives the ability to change the way how the textures should be created such as defining the quality and the color type. It can also be defined if some or all types of EXT texture types are allowed or forbidden.

Definition at line 27 of file Textures.h.

Constructor & Destructor Documentation

Textures::~Textures ( void  )

Destructor.

Trys to free all textures with freeTextures() and after that clears the vector holding the generated texture numbers.

Definition at line 52 of file Textures.cpp.

Member Function Documentation

void Textures::bindTexture ( unsigned int  texture)

Binds a texture.

Binds the texture with the given index number as a GL_TEXTURE_2D for use with OpenGL.

Parameters
texturethe number of the texture, used for indexing the texture vector

Definition at line 246 of file Textures.cpp.

void Textures::changeColors ( bool  value)

Set's conversion between RGB and BGR on and off.

If 'true' is submitted, the red and blue components of a loaded texture are changed. This could be used to create textures which seem to be varied.

Parameters
valuedetermines wheather conversion is active or not

Definition at line 72 of file Textures.cpp.

void Textures::freeTexture ( unsigned int  texture)

Frees texture memory.

If the index of the given texture is valid and an OpenGL generated texture number has been assigned to it, the texture space is freed. All variables for this texture id are resetted to defaults.

Parameters
texturethe number of the texture used for indexing the vector of textures

Definition at line 82 of file Textures.cpp.

Textures * Textures::getTextures ( void  )
static

Public access to singleton object.

The public access for the singleton object. If called for the first time a new instance of Textures is created, otherwise the existing instance is returned.

Returns
A pointer to the instance of the class

Definition at line 31 of file Textures.cpp.

void Textures::loadTexture ( unsigned int  texture,
std::string  filename 
)

Loads a texture from a file into a texture slot.

Loads a texture from a file. The texture is accessed by an texture value which is send by the application. After that a new texture name is generated by OpenGL. If the texture value is already assigned to a texture, the old texture is deleted and the OpenGL texture name is freed.

Parameters
filenamethe filename of the texture
texturethe number of the texture, used for indexing the texture vector

Definition at line 104 of file Textures.cpp.

void Textures::loadTexture ( unsigned int  texture,
TextureLoader loader 
)

Loads a texture from memory into a texture slot.

Loads a texture from memory. The texture has to be provided by a TextureLoader.

Parameters
textureThe index of the texture. Used for indexing the texture vector
loaderPointer to an TextureLoader instance that holds the picture data.

Definition at line 170 of file Textures.cpp.

void Textures::reserve ( unsigned int  textureCount)

Reserves space for textures in the vector.

Reserves space in order to save textures and spare some time because the vector does not need to resize itself. The values are initialized with -1 which is the value used for testing if a slot is uninitialized. If the submitted value is smaller than the current size of the vector, it is ignored. Note that it is possible to load more than the reserved number of textures.

Parameters
textureCountthe space that should be reserved

Definition at line 221 of file Textures.cpp.


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