Changeset 7687 in orxonox.OLD for branches/water/src/lib/graphics/importer/texture.cc
- Timestamp:
- May 18, 2006, 3:16:46 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/water/src/lib/graphics/importer/texture.cc
r7221 r7687 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 } … … 264 293 glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT); 265 294 266 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR /*_MIPMAP_LINEAR*/);295 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 267 296 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 268 297
Note: See TracChangeset
for help on using the changeset viewer.