mElite
1.0
An Elite clone based on TextElite by Jan-Philipp Kappmeier and Melanie Schmidt.
|
The a loader that can set up the image data of a graphics file as an OpenGL texture. More...
#include <TextureLoader.h>
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. | |
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.
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.
|
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.
colorMode | The 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.
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.
Definition at line 92 of file TextureLoader.cpp.
unsigned int TextureLoader::getHeight | ( | void | ) |
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.
Definition at line 106 of file TextureLoader.cpp.
unsigned int TextureLoader::getWidth | ( | void | ) |
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.
Definition at line 218 of file TextureLoader.cpp.
|
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.
data | A pointer to the actual image data. |
width | The width of the image. |
height | The height of the image. |
bpp | The color depth of the image in bits per pixel . Has to be 3 or 4. |
Definition at line 47 of file TextureLoader.cpp.
|
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.
bpp | The width. |
Definition at line 137 of file TextureLoader.cpp.
|
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.
format | The width. |
Definition at line 147 of file TextureLoader.cpp.
|
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.
height | The width. |
Definition at line 127 of file TextureLoader.cpp.
|
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.
image | a pointer to an array containing image arrays. The first of them is set as actual image. |
Definition at line 157 of file TextureLoader.cpp.
|
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.
[in,out] | image | a poionter to an array containing the actual image data |
Definition at line 168 of file TextureLoader.cpp.
|
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.
width | The 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.
value | decides, 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.
Definition at line 204 of file TextureLoader.cpp.
|
pure virtual |
Implemented in TextureLoaderBMP, and TextureLoaderTGA.