Changeset 7522 in orxonox.OLD for branches/bsp_model/src/lib
- Timestamp:
- May 3, 2006, 4:42:35 PM (19 years ago)
- Location:
- branches/bsp_model/src/lib/graphics/importer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/bsp_model/src/lib/graphics/importer/texture.cc
r7465 r7522 34 34 Texture::Texture(const std::string& imageName, GLenum target) 35 35 { 36 this->init(); 37 38 if (!imageName.empty()) 39 { 40 this->setName(imageName); 41 this->loadImage(imageName, target); 42 } 43 } 44 45 Texture::Texture(SDL_Surface* surface, GLenum target) 46 { 47 this->init(); 48 49 if(surface != NULL) 50 { 51 this->loadSurface(surface, target); 52 53 } 54 } 55 56 void Texture::init() 57 { 36 58 this->setClassID(CL_TEXTURE, "Texture"); 37 59 … … 40 62 this->image = NULL; 41 63 this->priority = 0.5; 42 43 if (!imageName.empty()) 44 { 45 this->setName(imageName); 46 this->loadImage(imageName, target); 47 } 48 } 49 64 } 50 65 51 66 /** … … 64 79 65 80 /** 66 * loads an Image from a file to a Texture81 * @brief loads an Image from a file to a Texture 67 82 * @param imageName The image to load 68 83 */ … … 71 86 if (Texture::texturesEnabled) 72 87 { 73 if (this->image != NULL)74 {75 SDL_FreeSurface(this->image);76 this->image = NULL;77 }78 if (this->texture != 0)79 {80 glDeleteTextures(1, &this->texture);81 this->texture = 0;82 }83 88 if (!imageName.empty()) 84 89 { 85 90 SDL_Surface* tmpSurf; 86 if (this->texture != 0 && glIsTexture(this->texture)) 87 glDeleteTextures(1, &this->texture); 91 88 92 // load the new Image to memory 89 93 tmpSurf = IMG_Load(imageName.c_str()); 90 94 if(tmpSurf != NULL) 91 95 { 92 PRINTF(4)("loading Image %s\n", imageName); 93 bool hasAlpha; 94 SDL_Surface* newSurf = this->prepareSurface(tmpSurf, hasAlpha); 95 if (newSurf != NULL) 96 { 97 this->setSurface(newSurf); 98 this->setAlpha(hasAlpha); 99 this->setTexture(Texture::loadTexToGL(newSurf, target)); 100 } 101 96 this->loadSurface(tmpSurf, target); 102 97 SDL_FreeSurface(tmpSurf); 103 98 return true; … … 114 109 PRINTF(2)("Image-Name not specified\n"); 115 110 return false; 111 } 112 } 113 return false; 114 } 115 116 /** 117 * @brief Loads an SDL_Surface. 118 */ 119 bool Texture::loadSurface(SDL_Surface* surface, GLenum target) 120 { 121 if (Texture::texturesEnabled) 122 { 123 // some image was loaded before 124 if (this->image != NULL) 125 { 126 SDL_FreeSurface(this->image); 127 this->image = NULL; 128 } 129 130 // unload the old Texture. 131 if (this->texture != 0 && glIsTexture(this->texture)) 132 { 133 glDeleteTextures(1, &this->texture); 134 this->texture = 0; 135 } 136 137 bool hasAlpha; 138 SDL_Surface* newSurf = this->prepareSurface(surface, hasAlpha); 139 if (newSurf != NULL) 140 { 141 this->setSurface(newSurf); 142 this->setAlpha(hasAlpha); 143 this->setTexture(Texture::loadTexToGL(newSurf, target)); 144 return true; 116 145 } 117 146 } -
branches/bsp_model/src/lib/graphics/importer/texture.h
r7221 r7522 19 19 public: 20 20 Texture(const std::string& imageName = "", GLenum target = GL_TEXTURE_2D); 21 // Texture(TEXTURE_TYPE type, int resolution);21 Texture(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D); 22 22 virtual ~Texture(); 23 23 24 24 bool loadImage(const std::string& imageName, GLenum target = GL_TEXTURE_2D); 25 bool loadSurface(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D); 25 26 virtual bool rebuild(); 26 27 … … 28 29 inline GLuint getTexture() const { return this->texture; }; 29 30 /** @returns true if texture has alpha, false otherwise */ 30 inline bool hasAlpha() const {return bAlpha;}31 inline bool hasAlpha() const {return bAlpha; } 31 32 /** @returns the stored image of this Texture */ 32 33 const SDL_Surface* const getStoredImage() const { return this->image; }; … … 43 44 44 45 protected: 45 46 46 bool setSurface(SDL_Surface* newSurface); 47 47 bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; }; 48 48 bool setTexture(GLuint texture) { this->texture = texture; }; 49 49 50 private: 51 void init(); 50 52 51 53 private:
Note: See TracChangeset
for help on using the changeset viewer.