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
Public Member Functions | Protected Member Functions | List of all members
TextureLoader Class Referenceabstract

The a loader that can set up the image data of a graphics file as an OpenGL texture. More...

#include <TextureLoader.h>

Inheritance diagram for TextureLoader:
TextureLoaderBMP TextureLoaderTGA

Public Member Functions

 TextureLoader (void)
 Default constructor. Initializes variables and does nothing.
 
 ~TextureLoader (void)
 Destructor. Frees image data, if an image has been loaded.
 
virtual bool load (const std::string &filename)=0
 
virtual bool write (const std::string &filename)=0
 
bool load (BYTE *data, unsigned int width, unsigned int height, unsigned int bpp)
 Load an image from memory.
 
unsigned int getWidth (void)
 Returns the width of the image.
 
unsigned int getHeight (void)
 Gets the height of the image.
 
unsigned int getBPP (void)
 Gets the bits per pixel of the image. This is usually 24 or 32.
 
GLenum getFormat (void)
 Gets the OpenGL format of the image data.
 
BYTE * getImage ()
 Gets the actual image data as byte array.
 
void useBGR (bool value)
 Sets the color order to blue, green, red by force.
 
bool useBGR (void)
 Determines if BGR coloring is used, or not.
 
bool isBGR (void)
 Trys to decide, if BGR is the appropriate ording for the format of the current image.
 
void toRGB (void)
 Converts the image from BGR to RBG, if the image data is in BGR ordering.
 
void toBGR (void)
 Converts the image from RGB to BGR, if the image data is in RGB ordering.
 

Protected Member Functions

void setWidth (unsigned int width)
 Sets the width of the image.
 
void setHeight (unsigned int height)
 Sets the height of the image.
 
void setBPP (unsigned int bpp)
 Sets the number of bits per pixel for the image.
 
void setFormat (GLenum format)
 Sets the format of the image.
 
void setImage (BYTE **image)
 Sets the image data.
 
void setImage (BYTE *image)
 Sets the image data.
 
void bgr2rgb (unsigned __int8 colorMode)
 Convert the image data from BGR to RGB format.
 

Detailed Description

The a loader that can set up the image data of a graphics file as an OpenGL texture.

The class itself does not provide ability to load a file, but provides virtual methods. For derived loaders, these methods must be implemented. Besides loading from hard drives, the loader can also load from data stored in memory. This can be used to render images that are used as textures.

Definition at line 26 of file TextureLoader.h.

Constructor & Destructor Documentation

TextureLoader::TextureLoader ( void  )

Default constructor. Initializes variables and does nothing.

Definition at line 12 of file TextureLoader.cpp.

TextureLoader::~TextureLoader ( void  )

Destructor. Frees image data, if an image has been loaded.

Definition at line 24 of file TextureLoader.cpp.

Member Function Documentation

void TextureLoader::bgr2rgb ( unsigned __int8  colorMode)
protected

Convert the image data from BGR to RGB format.

The format description describes the byte order of red, green and blue bytes in memory.

Parameters
colorModeThe color mode.

Definition at line 179 of file TextureLoader.cpp.

unsigned int TextureLoader::getBPP ( void  )

Gets the bits per pixel of the image. This is usually 24 or 32.

Returns
The bits per pixel.

Definition at line 81 of file TextureLoader.cpp.

GLenum TextureLoader::getFormat ( void  )

Gets the OpenGL format of the image data.

This may be RGBA for a RGB encoded image containing an alpha channel.

Returns
The format.

Definition at line 92 of file TextureLoader.cpp.

unsigned int TextureLoader::getHeight ( void  )

Gets the height of the image.

Returns
The height.

Definition at line 72 of file TextureLoader.cpp.

BYTE * TextureLoader::getImage ( )

Gets the actual image data as byte array.

The meaning of the data depends on the format of the image. In a 32 bit image with alpha channel, four bytes contain the information of 1 pixel.

Returns
a pointer to the image data

Definition at line 106 of file TextureLoader.cpp.

unsigned int TextureLoader::getWidth ( void  )

Returns the width of the image.

Returns
The width.

Definition at line 63 of file TextureLoader.cpp.

bool TextureLoader::isBGR ( void  )

Trys to decide, if BGR is the appropriate ording for the format of the current image.

For the formats GL_RGB and GL_RGBA, false is returned. For GL_BGR_EXT true is returned. As for all other formats, nothing special is known, as a default value, false is returned (as rgb is the 'natural' ordering).

The conversion only takes place, if GL_BGR_EXT is provided by the OpenGL implementation.

Returns
true, if the current format should be assumed to be BGR

Definition at line 218 of file TextureLoader.cpp.

virtual bool TextureLoader::load ( const std::string &  filename)
pure virtual

Implemented in TextureLoaderBMP, and TextureLoaderTGA.

bool TextureLoader::load ( BYTE *  data,
unsigned int  width,
unsigned int  height,
unsigned int  bpp 
)

Load an image from memory.

/* Loads an image from memory into the texture loader. The size of the image and the color dephth has to be submitted. If the dephth has the wrong value, false is returned. The picture information is stored in the class without any checking. It is assumed that the data is in RGB format and the corrisponding values GL_RGB or GL_RGBA are set. For more complex loading from memory this function has to be overridden by inheritors.

Parameters
dataA pointer to the actual image data.
widthThe width of the image.
heightThe height of the image.
bppThe color depth of the image in bits per pixel . Has to be 3 or 4.
Returns
Usually true is returned as no presumption about the image data is made.

Definition at line 47 of file TextureLoader.cpp.

void TextureLoader::setBPP ( unsigned int  bpp)
protected

Sets the number of bits per pixel for the image.

The width, height and format information are used to reserve the necessary space in memory for an image.

Parameters
bppThe width.

Definition at line 137 of file TextureLoader.cpp.

void TextureLoader::setFormat ( GLenum  format)
protected

Sets the format of the image.

The width, height and format information are used to reserve the necessary space in memory for an image.

Parameters
formatThe width.

Definition at line 147 of file TextureLoader.cpp.

void TextureLoader::setHeight ( unsigned int  height)
protected

Sets the height of the image.

The width, height and format information are used to reserve the necessary space in memory for an image.

Parameters
heightThe width.

Definition at line 127 of file TextureLoader.cpp.

void TextureLoader::setImage ( BYTE **  image)
protected

Sets the image data.

The image data is an byte array residing in memory. It may come from a capture taken from the OpenGL rendering out.

Parameters
imagea pointer to an array containing image arrays. The first of them is set as actual image.

Definition at line 157 of file TextureLoader.cpp.

void TextureLoader::setImage ( BYTE *  image)
protected

Sets the image data.

The imaga data is an byte array residing in memory. It may come from a capture taken from the OpenGL rendering out.

Parameters
[in,out]imagea poionter to an array containing the actual image data

Definition at line 168 of file TextureLoader.cpp.

void TextureLoader::setWidth ( unsigned int  width)
protected

Sets the width of the image.

The width, height and format information are used to reserve the necessary space in memory for an image.

Parameters
widthThe width.

Definition at line 117 of file TextureLoader.cpp.

void TextureLoader::toBGR ( void  )

Converts the image from RGB to BGR, if the image data is in RGB ordering.

The conversion only takes place, if GL_BGR_EXT is provided by the OpenGL implementation.

Definition at line 252 of file TextureLoader.cpp.

void TextureLoader::toRGB ( void  )

Converts the image from BGR to RBG, if the image data is in BGR ordering.

The conversion only takes place, if GL_BGR_EXT is provided by the OpenGL implementation.

Definition at line 237 of file TextureLoader.cpp.

void TextureLoader::useBGR ( bool  value)

Sets the color order to blue, green, red by force.

With this ordering, the colors are changed and not displayed correctly, if the original ordering war RGB.

Parameters
valuedecides, if BGR ordering should be used, or not

Definition at line 195 of file TextureLoader.cpp.

bool TextureLoader::useBGR ( void  )

Determines if BGR coloring is used, or not.

Returns
true if BGR ordering is used

Definition at line 204 of file TextureLoader.cpp.

virtual bool TextureLoader::write ( const std::string &  filename)
pure virtual

Implemented in TextureLoaderBMP, and TextureLoaderTGA.


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