Changeset 5858 in orxonox.OLD
- Timestamp:
- Dec 1, 2005, 8:03:35 PM (19 years ago)
- Location:
- trunk/src/lib/graphics/importer
- Files:
-
- 3 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/Makefile.am
r5463 r5858 9 9 md2Model.cc \ 10 10 material.cc \ 11 texture.cc 11 texture.cc \ 12 multi_frame_texture.cc 12 13 13 14 … … 20 21 material.h \ 21 22 texture.h \ 23 multi_frame_texture.h \ 22 24 anorms.h \ 23 25 anormtab.h -
trunk/src/lib/graphics/importer/multi_frame_texture.cc
r5856 r5858 16 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER 17 17 18 #include " texture.h"18 #include "multi_frame_texture.h" 19 19 20 20 #include "debug.h" 21 21 #include "graphics_engine.h" 22 23 #include <stdarg.h> 22 24 23 25 #ifdef HAVE_SDL_IMAGE_H … … 30 32 * Constructor for a Texture 31 33 */ 32 Texture::Texture(const char* imageName)34 MultiFrameTexture::MultiFrameTexture(unsigned int count, ...) 33 35 { 34 36 this->setClassID(CL_TEXTURE, "Texture"); 35 36 this->bAlpha = false;37 this->texture = 0;38 this->image = NULL;39 40 if (imageName != NULL)41 {42 this->setName(imageName);43 this->loadImage(imageName);44 }45 }46 47 /**48 * Destructor of a Texture49 50 Frees Data, and deletes the textures from GL51 */52 Texture::~Texture()53 {54 if (this->texture != 0)55 glDeleteTextures(1, &this->texture);56 if (this->image != NULL)57 SDL_FreeSurface(this->image);58 }59 60 61 /**62 * loads an Image from a file to a Texture63 * @param imageName The image to load64 */65 bool Texture::loadImage(const char* imageName)66 {67 if (GraphicsEngine::texturesEnabled)68 {69 if (this->image != NULL)70 {71 SDL_FreeSurface(this->image);72 this->image = NULL;73 }74 if (this->texture != 0)75 {76 glDeleteTextures(1, &this->texture);77 this->texture = 0;78 }79 if (imageName != NULL)80 {81 SDL_Surface* tmpSurf;82 if (this->texture != 0 && glIsTexture(this->texture))83 glDeleteTextures(1, &this->texture);84 // load the new Image to memory85 tmpSurf = IMG_Load(imageName);86 if(tmpSurf != NULL)87 {88 PRINTF(4)("loading Image %s\n", imageName);89 if (this->prepareSurface(tmpSurf))90 this->texture = Texture::loadTexToGL(this->image);91 92 SDL_FreeSurface(tmpSurf);93 return true;94 }95 else96 {97 PRINTF(1)("IMG_Load: %s\n", IMG_GetError());98 this->texture = 0;99 return false;100 }101 }102 else103 {104 PRINTF(2)("Image-Name not specified\n");105 return false;106 }107 }108 return false;109 }110 111 bool Texture::rebuild()112 {113 if (this->texture != 0 && glIsTexture(this->texture))114 {115 glDeleteTextures(1,&this->texture);116 this->texture = 0;117 }118 119 if (this->image != NULL)120 {121 PRINTF(3)("Reloading Texture of %s '%s'\n", this->getClassName(), this->getName());122 this->texture = loadTexToGL(this->image);123 }124 37 125 38 } 126 39 127 40 /** 128 * converts surface to a new SDL_Surface, that is loadable by openGL129 * @param surface the Surface to convert 130 * @returns a !!new!! Surface, that is loadable by openGL.131 132 bool Texture::prepareSurface(SDL_Surface* surface)41 * Destructor of a MultiFrameTexture 42 43 Frees Data, and deletes the textures from GL 44 */ 45 MultiFrameTexture::~MultiFrameTexture() 133 46 { 134 PRINTF(4)("Loading texture to OpenGL-Environment.\n");135 136 SDL_Surface* putSurface;137 SDL_Rect area;138 Uint32 saved_flags;139 Uint8 saved_alpha;140 141 putSurface = SDL_CreateRGBSurface(SDL_SWSURFACE,142 surface->w, surface->h,143 32,144 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */145 0x000000FF,146 0x0000FF00,147 0x00FF0000,148 0xFF000000149 #else150 0xFF000000,151 0x00FF0000,152 0x0000FF00,153 0x000000FF154 #endif155 );156 if ( putSurface == NULL )157 {158 this->setSurface(NULL);159 return false;160 }161 162 /* Save the alpha blending attributes */163 saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);164 saved_alpha = surface->format->alpha;165 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {166 SDL_SetAlpha(surface, 0, 0);167 }168 169 /* Copy the surface into the GL texture image */170 area.x = 0;171 area.y = 0;172 area.w = surface->w;173 area.h = surface->h;174 SDL_BlitSurface(surface, &area, putSurface, &area);175 176 /* Restore the alpha blending attributes */177 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA )178 {179 SDL_SetAlpha(surface, saved_flags | SDL_OPENGL, saved_alpha);180 this->bAlpha = true;181 }182 183 return (this->setSurface(putSurface));184 }185 186 bool Texture::setSurface(SDL_Surface* newSurface)187 {188 if (this->image != NULL)189 SDL_FreeSurface(this->image);190 191 this->image = newSurface;192 193 return (this->image != NULL);194 47 } 195 48 196 49 197 /** 198 * Loads a Texture to the openGL-environment. 199 * @param surface the Image to load to openGL 200 * @returns The ID of the texture. 201 */ 202 GLuint Texture::loadTexToGL (const SDL_Surface* surface) 50 51 bool MultiFrameTexture::rebuild() 203 52 { 204 // if (this->texture != 0 && glIsTexture(this->texture)) 205 // glDeleteTextures(1, &this->texture); 206 // this->texture = 0; 53 // if (this->texture != 0 && glIsMultiFrameTexture(this->texture)) 54 // { 55 // glDeleteMultiFrameTextures(1,&this->texture); 56 // this->texture = 0; 57 // } 58 // 59 // if (this->image != NULL) 60 // { 61 // PRINTF(3)("Reloading MultiFrameTexture of %s '%s'\n", this->getClassName(), this->getName()); 62 // this->texture = loadTexToGL(this->image); 63 // } 207 64 208 GLuint texture;209 210 if (surface == NULL)211 return 0;212 213 /* Create an OpenGL texture for the image */214 glGenTextures(1, &texture);215 glBindTexture(GL_TEXTURE_2D, texture);216 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);217 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);218 // build the Texture219 glTexImage2D(GL_TEXTURE_2D,220 0,221 GL_RGBA,222 surface->w, surface->h,223 0,224 GL_RGBA,225 GL_UNSIGNED_BYTE,226 surface->pixels);227 // build the MipMaps228 gluBuild2DMipmaps(GL_TEXTURE_2D,229 GL_RGBA,230 surface->w,231 surface->h,232 GL_RGBA,233 GL_UNSIGNED_BYTE,234 surface->pixels);235 glBindTexture(GL_TEXTURE_2D, 0);236 return texture;237 65 } -
trunk/src/lib/graphics/importer/multi_frame_texture.h
r5856 r5858 4 4 */ 5 5 6 #ifndef _ TEXTURE_H7 #define _ TEXTURE_H6 #ifndef _MULTI_FRAME_TEXTURE_H 7 #define _MULTI_FRAME_TEXTURE_H 8 8 9 #include " base_object.h"9 #include "texture.h" 10 10 11 11 #include "glincl.h" 12 #include <vector> 12 13 13 14 /* Forward Declaration */ 14 15 struct SDL_Surface; 15 16 16 //! an enumerator for different procedural texture-types17 typedef enum TEXTURE_TYPE { TEXTURE_RADIAL_ALIAS,18 TEXTURE_NOISE };19 20 17 //! A Class, that reads in Textures from different fileformats. 21 class Texture : public BaseObject18 class MultiFrameTexture : public Texture 22 19 { 23 20 public: 24 Texture(const char* imageName = NULL);21 MultiFrameTexture(unsigned int count, ...); 25 22 // Texture(TEXTURE_TYPE type, int resolution); 26 ~ Texture();23 ~MultiFrameTexture(); 27 24 28 bool loadImage (const char* imageName);25 bool loadImages(unsigned int cound, ...); 29 26 bool rebuild(); 30 27 31 28 /** @returns The textureID of this texture. */ 32 inline GLuint getTexture() const { return this->texture; }; 33 /** @returns true if texture has alpha, false otherwise */ 34 inline bool hasAlpha() const {return bAlpha;} 29 inline GLuint getFrameTexture(unsigned int frameNumber);// const { return this->textures; }; 35 30 36 static GLuint loadTexToGL (const SDL_Surface* surface); 37 38 const SDL_Surface* const getStoredImage() { return this->image; }; 39 40 protected: 41 bool prepareSurface(SDL_Surface* input); 42 bool setSurface(SDL_Surface* newSurface); 43 bool setTexture(GLuint texture) { this->texture = texture; }; 44 31 const SDL_Surface* const getFrameImage() const { }; 45 32 46 33 private: 47 GLuint texture; //!< The Texture-ID of opengl from this Texture. 48 bool bAlpha; //!< if the texture has an alpha channel. 49 SDL_Surface* image; //!< The SDL_Surfce that stores the Texture on it. 34 std::vector<GLuint> textures; //!< The Texture-ID of opengl from this Texture. 35 std::vector<SDL_Surface*> images; //!< The SDL_Surfce that stores the Texture on it. 50 36 }; 51 37 52 #endif /* _ TEXTURE_H */38 #endif /* _MULTI_FRAME_TEXTURE_H */ -
trunk/src/lib/graphics/importer/texture.cc
r5856 r5858 19 19 20 20 #include "debug.h" 21 #include "graphics_engine.h" 22 21 22 // INCLUDING SDL_Image 23 23 #ifdef HAVE_SDL_IMAGE_H 24 24 #include <SDL_image.h> … … 58 58 } 59 59 60 61 60 /** 62 61 * loads an Image from a file to a Texture … … 65 64 bool Texture::loadImage(const char* imageName) 66 65 { 67 if ( GraphicsEngine::texturesEnabled)66 if (Texture::texturesEnabled) 68 67 { 69 68 if (this->image != NULL) … … 195 194 196 195 196 bool Texture::texturesEnabled = true; 197 198 /** 199 * enables, disables textures 200 * @param texturesEnabled true if the textures should be enabled 201 */ 202 void Texture::setTextureEnableState(bool texturesEnabled) 203 { 204 Texture::texturesEnabled = texturesEnabled; 205 } 206 207 208 ////////////////////////////////////// 209 // UTILITY FUNCTIONALITY OF TEXTURE // 210 ////////////////////////////////////// 197 211 /** 198 212 * Loads a Texture to the openGL-environment. -
trunk/src/lib/graphics/importer/texture.h
r5857 r5858 14 14 struct SDL_Surface; 15 15 16 //! an enumerator for different procedural texture-types17 typedef enum TEXTURE_TYPE { TEXTURE_RADIAL_ALIAS,18 TEXTURE_NOISE };19 20 16 //! A Class, that reads in Textures from different fileformats. 21 17 class Texture : public BaseObject … … 27 23 28 24 bool loadImage(const char* imageName); 29 bool rebuild();25 virtual bool rebuild(); 30 26 31 27 /** @returns The textureID of this texture. */ … … 33 29 /** @returns true if texture has alpha, false otherwise */ 34 30 inline bool hasAlpha() const {return bAlpha;} 31 /** @returns the stored image of this Texture */ 32 const SDL_Surface* const getStoredImage() const { return this->image; }; 35 33 36 static GLuint loadTexToGL (const SDL_Surface* surface);37 34 38 const SDL_Surface* const getStoredImage() { return this->image; };39 35 40 36 static void setTextureEnableState(bool texturesEnabled); 41 37 /** @returns true if Textures are enabled */ 42 38 inline static bool getTextureEnableState() { return Texture::texturesEnabled; }; 39 40 // Utility functionality: 41 static GLuint loadTexToGL (const SDL_Surface* surface); 43 42 44 43 protected:
Note: See TracChangeset
for help on using the changeset viewer.