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
TextureLoader.cpp
Go to the documentation of this file.
1 
7 #include "TextureLoader.h"
8 
13  m_width = 0;
14  m_height = 0;
15  image2d = NULL;
16  image = NULL;
17  m_format = 0;
18  m_useBGR = true;
19 }
20 
25  if( image2d ) {
26  delete [] image2d[0];
27  delete [] image2d;
28  } else {
29  delete [] image;
30  }
31 }
32 
47 bool TextureLoader::load( BYTE *data, unsigned int width, unsigned int height, unsigned int bpp) {
48  if( bpp < 3 || bpp > 4 )
49  return false;
50  setWidth( width );
51  setHeight( height );
52  setBPP( bpp );
53  setImage( data );
54  this->setFormat( bpp == 3 ? GL_RGB : GL_RGBA );
55  return true;
56 }
57 
63 unsigned int TextureLoader::getWidth() {
64  return m_width;
65 }
66 
72 unsigned int TextureLoader::getHeight() {
73  return m_height;
74 }
75 
81 unsigned int TextureLoader::getBPP() {
82  return m_bpp;
83 }
84 
93  return m_format;
94 }
95 
107  return image;
108 }
109 
117 void TextureLoader::setWidth( unsigned int width ) {
118  m_width = width;
119 }
120 
122 
127 void TextureLoader::setHeight( unsigned int height ) {
128  m_height = height;
129 }
130 
132 
137 void TextureLoader::setBPP( unsigned int bpp ) {
138  m_bpp = bpp;
139 }
140 
142 
147 void TextureLoader::setFormat( GLenum format ) {
148  m_format = format;
149 }
150 
152 
157 void TextureLoader::setImage( BYTE **image ) {
158  image2d = image;
159  this->image = image[0];
160 }
161 
163 
168 void TextureLoader::setImage( BYTE *image ) {
169  image2d = NULL;
170  this->image = image;
171 }
172 
174 
179 void TextureLoader::bgr2rgb( unsigned __int8 colorMode ) {
180  BYTE tempColor;
181  for( unsigned long index = 0; index < m_width * m_height * colorMode; index += colorMode ) {
182  tempColor = getImage()[index];
183  getImage()[index] = getImage()[index + 2];
184  getImage()[index + 2] = tempColor;
185  }
186 }
187 
189 
195 void TextureLoader::useBGR( bool value ) {
196  m_useBGR = value;
197 }
198 
200 
204 bool TextureLoader::useBGR( void ) {
205  return m_useBGR;
206 }
207 
209 
219 #ifdef GL_BGR_EXT
220  if( getFormat() == GL_BGR_EXT )
221  return true;
222  if( getFormat() == GL_RGB || getFormat() == GL_RGBA )
223  return false;
224  // return false, if nothing about format is known ;)
225  return false;
226 #else
227  return false;
228 #endif
229 }
230 
232 
238 #ifdef GL_BGR_EXT
239  if( getFormat() == GL_BGR_EXT ) {
240  bgr2rgb( 3 );
241  setFormat( GL_RGB );
242  }
243 #endif
244 }
245 
247 
253 #ifdef GL_BGR_EXT
254  if( getFormat() == GL_RGB ) {
255  bgr2rgb( 3 );
256  setFormat( GL_BGR_EXT );
257  }
258 #endif
259 }