Changeset 6859 in orxonox.OLD for trunk/src/lib/graphics/importer
- Timestamp:
- Jan 30, 2006, 5:24:12 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/texture.cc
r6634 r6859 70 70 { 71 71 if (Texture::texturesEnabled) 72 { 73 if (this->image != NULL) 72 74 { 73 if (this->image != NULL) 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 if (imageName != NULL) 84 { 85 SDL_Surface* tmpSurf; 86 if (this->texture != 0 && glIsTexture(this->texture)) 87 glDeleteTextures(1, &this->texture); 88 // load the new Image to memory 89 tmpSurf = IMG_Load(imageName); 90 if(tmpSurf != NULL) 91 { 92 PRINTF(4)("loading Image %s\n", imageName); 93 bool hasAlpha; 94 SDL_Surface* newSurf = this->prepareSurface(tmpSurf, hasAlpha); 95 if (newSurf != NULL) 74 96 { 75 SDL_FreeSurface(this->image); 76 this->image = NULL; 97 this->setSurface(newSurf); 98 this->setAlpha(hasAlpha); 99 this->setTexture(Texture::loadTexToGL(newSurf, target)); 77 100 } 78 if (this->texture != 0) 79 { 80 glDeleteTextures(1, &this->texture); 81 this->texture = 0; 82 } 83 if (imageName != NULL) 84 { 85 SDL_Surface* tmpSurf; 86 if (this->texture != 0 && glIsTexture(this->texture)) 87 glDeleteTextures(1, &this->texture); 88 // load the new Image to memory 89 tmpSurf = IMG_Load(imageName); 90 if(tmpSurf != NULL) 91 { 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 102 SDL_FreeSurface(tmpSurf); 103 return true; 104 } 105 else 106 { 107 PRINTF(1)("IMG_Load: %s\n", IMG_GetError()); 108 this->texture = 0; 109 return false; 110 } 111 } 101 102 SDL_FreeSurface(tmpSurf); 103 return true; 104 } 112 105 else 113 { 114 PRINTF(2)("Image-Name not specified\n"); 115 return false; 116 } 106 { 107 PRINTF(1)("IMG_Load: %s\n", IMG_GetError()); 108 this->texture = 0; 109 return false; 110 } 117 111 } 112 else 113 { 114 PRINTF(2)("Image-Name not specified\n"); 115 return false; 116 } 117 } 118 118 return false; 119 119 } … … 127 127 { 128 128 if (this->texture != 0) 129 130 131 132 133 129 { 130 if (glIsTexture(this->texture)) 131 glDeleteTextures(1,&this->texture); 132 this->setTexture(0); 133 } 134 134 135 135 if (this->image != NULL) 136 137 138 139 136 { 137 PRINTF(3)("Reloading Texture of %s '%s'\n", this->getClassName(), this->getName()); 138 this->setTexture(loadTexToGL(this->image)); 139 } 140 140 } 141 141 … … 194 194 32, 195 195 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ 196 0x000000FF,197 0x0000FF00,198 0x00FF0000,199 0xFF000000196 0x000000FF, 197 0x0000FF00, 198 0x00FF0000, 199 0xFF000000 200 200 #else 201 0xFF000000,202 0x00FF0000,203 0x0000FF00,204 0x000000FF201 0xFF000000, 202 0x00FF0000, 203 0x0000FF00, 204 0x000000FF 205 205 #endif 206 206 ); … … 213 213 saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK); 214 214 saved_alpha = surface->format->alpha; 215 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { 215 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) 216 { 216 217 SDL_SetAlpha(surface, 0, 0); 217 218 } … … 242 243 GLuint Texture::loadTexToGL (const SDL_Surface* surface, GLenum target) const 243 244 { 244 // if (this->texture != 0 && glIsTexture(this->texture))245 // glDeleteTextures(1, &this->texture);246 // this->texture = 0;245 // if (this->texture != 0 && glIsTexture(this->texture)) 246 // glDeleteTextures(1, &this->texture); 247 // this->texture = 0; 247 248 248 249 int errorCode = 0; //!< the error code for the texture loading functions … … 283 284 GL_UNSIGNED_BYTE, 284 285 surface->pixels); 286 printf("%s, w:%d h:%d, 0x%x\n", this->getName(), surface->w, surface->h, target); 285 287 286 288 // build the MipMaps automaticaly … … 296 298 PRINTF(1)("Error while loading texture (mipmap generation), gluBuild2DMipmaps returned %i\n", errorCode); 297 299 298 // Deselect newly built texture, as we do not want to display with this texture.299 if (target == GL_TEXTURE_2D)300 glBindTexture(target, 0);301 302 300 return texture; 303 301 }
Note: See TracChangeset
for help on using the changeset viewer.