| 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 "stdincl.h" | 
|---|
| 13 | #ifdef HAVE_SDL_SDL_IMAGE_H | 
|---|
| 14 | #include <SDL/SDL_image.h> | 
|---|
| 15 | #else | 
|---|
| 16 | // IMAGE LIBS // | 
|---|
| 17 | #ifdef HAVE_JPEGLIB_H | 
|---|
| 18 | extern "C"{         // This has to be done, because not a c++ lib | 
|---|
| 19 | #include <jpeglib.h> | 
|---|
| 20 | } | 
|---|
| 21 | #endif /* HAVE_JPEGLIB_H */ | 
|---|
| 22 | #ifdef HAVE_PNG_H | 
|---|
| 23 | #include <png.h> | 
|---|
| 24 | #endif /* HAVE_PNG_H */ | 
|---|
| 25 | #endif /* HAVE_SDL_SDL_IMAGE_H */ | 
|---|
| 26 |  | 
|---|
| 27 |  | 
|---|
| 28 |  | 
|---|
| 29 | //! Class to handle lists of paths. | 
|---|
| 30 | /** | 
|---|
| 31 |    \todo Ability to return Paths by itself. | 
|---|
| 32 |  | 
|---|
| 33 |    It is simple to use, and good, for all PathList you want. | 
|---|
| 34 |    just create a new Pathlist, and add Paths. | 
|---|
| 35 | */ | 
|---|
| 36 | class PathList | 
|---|
| 37 | { | 
|---|
| 38 |  private: | 
|---|
| 39 |   PathList(); | 
|---|
| 40 |   static PathList* firstPath; //!< A static Pointer to the first PathList in the List. | 
|---|
| 41 |  public: | 
|---|
| 42 |   PathList(char* pName); | 
|---|
| 43 |   ~PathList(); | 
|---|
| 44 |   static PathList* getInstance(void); | 
|---|
| 45 |    | 
|---|
| 46 |   void addPath (char* pName); | 
|---|
| 47 |   char* pathName;              //!< The Name of the current Path. | 
|---|
| 48 |   PathList* next;              //!< Pointer to the next Pathlist. | 
|---|
| 49 | }; | 
|---|
| 50 |  | 
|---|
| 51 | //! A Class, that reads in Textures from different fileformats. | 
|---|
| 52 | class Texture | 
|---|
| 53 | { | 
|---|
| 54 |  private: | 
|---|
| 55 |   //! Struct to handle Infos about an Image | 
|---|
| 56 |   struct Image | 
|---|
| 57 |   { | 
|---|
| 58 |     int rowSpan;    //!< The count of the rows this Image has. | 
|---|
| 59 |     GLuint width;   //!< The width of the Image. | 
|---|
| 60 |     GLuint height;  //!< The height of the Image. | 
|---|
| 61 |     GLuint bpp;     //!< BytesPerPixel | 
|---|
| 62 |     GLenum format;  //!< The Format of the PixelData | 
|---|
| 63 |     GLuint type;    //!< Type of the Image. | 
|---|
| 64 |     GLubyte *data;  //!< The Image Data comes here! DANGER: uncompressed data. | 
|---|
| 65 |   }; | 
|---|
| 66 |   Image* pImage;    //!< The data of an Image | 
|---|
| 67 |   GLuint texture;   //!< The Texture-ID of opengl from this Texture. | 
|---|
| 68 |   SDL_Surface* map; //!< The map SDL initializes for this element. | 
|---|
| 69 |   char* searchTextureInPaths(char* texName) const; | 
|---|
| 70 |   inline void swap(unsigned char &a, unsigned char &b); | 
|---|
| 71 |  public: | 
|---|
| 72 |   Texture(void); | 
|---|
| 73 |   ~Texture(void); | 
|---|
| 74 |   /** \returns The textureID of this texture.  */ | 
|---|
| 75 |   inline GLuint getTexture(void) {return this->texture;}  | 
|---|
| 76 |   bool loadTexToGL (Image* pImage); | 
|---|
| 77 |  | 
|---|
| 78 |   bool loadImage(char* imageName); | 
|---|
| 79 | #ifndef HAVE_SDL_SDL_IMAGE_H | 
|---|
| 80 |  | 
|---|
| 81 |   bool loadBMP (char* bmpName); | 
|---|
| 82 |  | 
|---|
| 83 |   bool loadJPG (char* jpgName); | 
|---|
| 84 |  | 
|---|
| 85 |   /// TGA /// | 
|---|
| 86 |  | 
|---|
| 87 |   bool loadTGA(const char * tgaName); | 
|---|
| 88 |   bool loadUncompressedTGA(const char * filename, FILE * fTGA); | 
|---|
| 89 |   bool loadCompressedTGA(const char * filename, FILE * fTGA); | 
|---|
| 90 |  | 
|---|
| 91 |   bool loadPNG(const char* pngName); | 
|---|
| 92 | #endif | 
|---|
| 93 |  | 
|---|
| 94 |  | 
|---|
| 95 | }; | 
|---|
| 96 |  | 
|---|
| 97 |  | 
|---|
| 98 |  | 
|---|
| 99 | #endif /* _TEXTURE_H */ | 
|---|