| 1 | /*! | 
|---|
| 2 |   \file texture.h | 
|---|
| 3 |   \brief Contains the texture class, that handles the reading of Images into Texutre-files. | 
|---|
| 4 |  | 
|---|
| 5 |   \todo free SDL-surface when deleting Material. | 
|---|
| 6 |   \todo delete imgNameWithPath after use creation. | 
|---|
| 7 | */ | 
|---|
| 8 |  | 
|---|
| 9 | #ifndef _TEXTURE_H | 
|---|
| 10 | #define _TEXTURE_H | 
|---|
| 11 |  | 
|---|
| 12 | #include "glincl.h" | 
|---|
| 13 |  | 
|---|
| 14 | #include "debug.h" | 
|---|
| 15 |  | 
|---|
| 16 | #ifdef HAVE_SDL_SDL_IMAGE_H | 
|---|
| 17 | #include <SDL/SDL_image.h> | 
|---|
| 18 | #else | 
|---|
| 19 | // IMAGE LIBS // | 
|---|
| 20 | #ifdef HAVE_JPEGLIB_H | 
|---|
| 21 | extern "C"{         // This has to be done, because not a c++ lib | 
|---|
| 22 | #include <jpeglib.h> | 
|---|
| 23 | } | 
|---|
| 24 | #endif /* HAVE_JPEGLIB_H */ | 
|---|
| 25 | #ifdef HAVE_PNG_H | 
|---|
| 26 | #include <png.h> | 
|---|
| 27 | #endif /* HAVE_PNG_H */ | 
|---|
| 28 | #endif /* HAVE_SDL_SDL_IMAGE_H */ | 
|---|
| 29 |  | 
|---|
| 30 | //! A Class, that reads in Textures from different fileformats. | 
|---|
| 31 | class Texture | 
|---|
| 32 | { | 
|---|
| 33 |  private: | 
|---|
| 34 |   //! Struct to handle Infos about an Image | 
|---|
| 35 |   struct Image | 
|---|
| 36 |   { | 
|---|
| 37 |     int rowSpan;    //!< The count of the rows this Image has. | 
|---|
| 38 |     GLuint width;   //!< The width of the Image. | 
|---|
| 39 |     GLuint height;  //!< The height of the Image. | 
|---|
| 40 |     GLuint bpp;     //!< BytesPerPixel | 
|---|
| 41 |     GLenum format;  //!< The Format of the PixelData | 
|---|
| 42 |     GLuint type;    //!< Type of the Image. | 
|---|
| 43 |     GLubyte *data;  //!< The Image Data comes here! DANGER: uncompressed data. | 
|---|
| 44 |   }; | 
|---|
| 45 |   Image* pImage;    //!< The data of an Image | 
|---|
| 46 |   GLuint texture;   //!< The Texture-ID of opengl from this Texture. | 
|---|
| 47 |   SDL_Surface* map; //!< The map SDL initializes for this element. | 
|---|
| 48 |   char* searchTextureInPaths(const char* texName) const; | 
|---|
| 49 |   inline void swap(unsigned char &a, unsigned char &b); | 
|---|
| 50 |  public: | 
|---|
| 51 |   Texture(void); | 
|---|
| 52 |   Texture(const char* imageName); | 
|---|
| 53 |   ~Texture(void); | 
|---|
| 54 |   /** \returns The textureID of this texture.  */ | 
|---|
| 55 |   inline GLuint getTexture(void) {return this->texture;}  | 
|---|
| 56 |   bool loadTexToGL (Image* pImage); | 
|---|
| 57 |  | 
|---|
| 58 |   bool loadImage(const char* imageName); | 
|---|
| 59 | #ifndef HAVE_SDL_SDL_IMAGE_H | 
|---|
| 60 |  | 
|---|
| 61 |   bool loadBMP (char* bmpName); | 
|---|
| 62 |  | 
|---|
| 63 |   bool loadJPG (char* jpgName); | 
|---|
| 64 |  | 
|---|
| 65 |   /// TGA /// | 
|---|
| 66 |  | 
|---|
| 67 |   bool loadTGA(const char * tgaName); | 
|---|
| 68 |   bool loadUncompressedTGA(const char * filename, FILE * fTGA); | 
|---|
| 69 |   bool loadCompressedTGA(const char * filename, FILE * fTGA); | 
|---|
| 70 |  | 
|---|
| 71 |   bool loadPNG(const char* pngName); | 
|---|
| 72 | #endif | 
|---|
| 73 |  | 
|---|
| 74 |  | 
|---|
| 75 | }; | 
|---|
| 76 |  | 
|---|
| 77 |  | 
|---|
| 78 |  | 
|---|
| 79 | #endif /* _TEXTURE_H */ | 
|---|