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