Changeset 5859 in orxonox.OLD for trunk/src/lib/graphics/importer/texture.cc
- Timestamp:
- Dec 1, 2005, 8:19:26 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/texture.cc
r5858 r5859 86 86 { 87 87 PRINTF(4)("loading Image %s\n", imageName); 88 if (this->prepareSurface(tmpSurf)) 89 this->texture = Texture::loadTexToGL(this->image); 88 bool hasAlpha; 89 SDL_Surface* newSurf = this->prepareSurface(tmpSurf, hasAlpha); 90 if (newSurf != NULL) 91 { 92 this->setSurface(newSurf); 93 this->setAlpha(hasAlpha); 94 this->setTexture(Texture::loadTexToGL(newSurf)); 95 } 90 96 91 97 SDL_FreeSurface(tmpSurf); … … 113 119 { 114 120 glDeleteTextures(1,&this->texture); 115 this-> texture = 0;121 this->setTexture(0); 116 122 } 117 123 … … 119 125 { 120 126 PRINTF(3)("Reloading Texture of %s '%s'\n", this->getClassName(), this->getName()); 121 this-> texture = loadTexToGL(this->image);127 this->setTexture(loadTexToGL(this->image)); 122 128 } 123 129 … … 127 133 * converts surface to a new SDL_Surface, that is loadable by openGL 128 134 * @param surface the Surface to convert 135 * @param hasAlpha if the newly created Surface has an alpha channel, true is returned otherwise false. 129 136 * @returns a !!new!! Surface, that is loadable by openGL. 130 137 */ 131 bool Texture::prepareSurface(SDL_Surface* surface)138 SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha) 132 139 { 133 140 PRINTF(4)("Loading texture to OpenGL-Environment.\n"); 134 141 135 SDL_Surface* putSurface;142 SDL_Surface* retSurface; 136 143 SDL_Rect area; 137 144 Uint32 saved_flags; 138 145 Uint8 saved_alpha; 139 146 140 putSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 147 hasAlpha = false; 148 retSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 141 149 surface->w, surface->h, 142 150 32, … … 153 161 #endif 154 162 ); 155 if ( putSurface == NULL )163 if ( retSurface == NULL ) 156 164 { 157 this->setSurface(NULL); 158 return false; 165 return NULL; 159 166 } 160 167 … … 171 178 area.w = surface->w; 172 179 area.h = surface->h; 173 SDL_BlitSurface(surface, &area, putSurface, &area);180 SDL_BlitSurface(surface, &area, retSurface, &area); 174 181 175 182 /* Restore the alpha blending attributes */ … … 177 184 { 178 185 SDL_SetAlpha(surface, saved_flags | SDL_OPENGL, saved_alpha); 179 this->bAlpha = true; 180 } 181 182 return (this->setSurface(putSurface)); 183 } 184 186 hasAlpha = true; 187 } 188 189 return (retSurface); 190 } 191 192 /** 193 * set the surface this Texture handles 194 * @param newSurface the new Surface to set as the image for this Texture. 195 * 196 * This deletes the old version of the stored Texture, 197 * and sets the newly given Surface as current. 198 */ 185 199 bool Texture::setSurface(SDL_Surface* newSurface) 186 200 {
Note: See TracChangeset
for help on using the changeset viewer.