Changeset 7727 in orxonox.OLD for trunk/src/lib/graphics/importer
- Timestamp:
- May 19, 2006, 2:25:15 PM (19 years ago)
- Location:
- trunk/src/lib/graphics/importer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/texture.cc
r7676 r7727 30 30 31 31 /** 32 * Constructor for a Texture32 * @brief Constructor for a Texture 33 33 */ 34 34 Texture::Texture(const std::string& imageName, GLenum target) … … 50 50 51 51 /** 52 * Destructor of a Texture53 54 55 */52 * @brief Destructor of a Texture 53 * 54 * Frees Data, and deletes the textures from GL 55 */ 56 56 Texture::~Texture() 57 57 { … … 64 64 65 65 /** 66 * loads an Image from a file to a Texture66 * @brief loads an Image from a file to a Texture 67 67 * @param imageName The image to load 68 68 */ … … 121 121 122 122 /** 123 * rebuilds the texture. 123 * @brief rebuilds the texture. 124 * 124 125 * reloads the Texture from Memory to OpenGL. 125 126 */ … … 142 143 143 144 /** 144 * set the surface this Texture handles145 * @brief set the surface this Texture handles 145 146 * @param newSurface the new Surface to set as the image for this Texture. 146 147 * … … 162 163 163 164 /** 164 * enables, disables textures165 * @brief enables, disables textures 165 166 * @param texturesEnabled true if the textures should be enabled 166 167 */ … … 175 176 ////////////////////////////////////// 176 177 /** 177 * converts surface to a new SDL_Surface, that is loadable by openGL178 * @brief converts surface to a new SDL_Surface, that is loadable by openGL 178 179 * @param surface the Surface to convert 179 180 * @param hasAlpha if the newly created Surface has an alpha channel, true is returned otherwise false. … … 182 183 SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha) const 183 184 { 185 assert(surface != NULL); 184 186 PRINTF(4)("Loading texture to OpenGL-Environment.\n"); 185 187 … … 190 192 191 193 hasAlpha = false; 192 retSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 194 int pixelDepth = 24; 195 196 /* Save the alpha blending attributes */ 197 saved_flags = surface->flags&(SDL_SRCALPHA | SDL_RLEACCELOK); 198 saved_alpha = surface->format->alpha; 199 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) 200 { 201 SDL_SetAlpha(surface, 0, 0); 202 hasAlpha = true; 203 pixelDepth = 32; 204 } 205 206 retSurface = SDL_CreateRGBSurface(SDL_HWSURFACE, 193 207 surface->w, surface->h, 194 32,208 pixelDepth, 195 209 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ 196 210 0x000000FF, … … 206 220 ); 207 221 if ( retSurface == NULL ) 208 {209 222 return NULL; 210 }211 212 /* Save the alpha blending attributes */213 saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);214 saved_alpha = surface->format->alpha;215 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA )216 {217 SDL_SetAlpha(surface, 0, 0);218 }219 223 220 224 /* Copy the surface into the GL texture image */ … … 237 241 238 242 /** 239 * Loads a Texture to the openGL-environment.243 * @brief Loads a Texture to the openGL-environment. 240 244 * @param surface the Image to load to openGL 241 245 * @returns The ID of the texture. … … 246 250 // glDeleteTextures(1, &this->texture); 247 251 // this->texture = 0; 252 assert(surface != NULL); 248 253 249 254 int errorCode = 0; //!< the error code for the texture loading functions … … 252 257 int mipmapWidth = 0; //!< the width of the mipmap 253 258 int mipmapHight = 0; //!< the height of the mipmap 254 255 256 if (surface == NULL) 257 return 0; 259 GLenum format = GL_RGB; 260 if (this->bAlpha) 261 { 262 format = GL_RGBA; 263 assert(surface->format->BitsPerPixel == 32); 264 } 265 else 266 { 267 assert(surface->format->BitsPerPixel == 24); 268 } 258 269 259 270 /* Create an OpenGL texture for the image */ … … 261 272 glBindTexture(target, texture); 262 273 274 // glTexImage2D(target, 0, format, 275 // surface->w, surface->h, 276 // 0, format, GL_UNSIGNED_BYTE, 277 // surface->pixels); 278 263 279 glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT); 264 280 glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT); … … 275 291 276 292 /* build the Texture OpenGL V >= 1.1 */ 277 glTexImage2D(target, 278 0, 279 GL_RGBA, 280 surface->w, 281 surface->h, 282 0, 283 GL_RGBA, 284 GL_UNSIGNED_BYTE, 285 surface->pixels); 293 286 294 // printf("%s, w:%d h:%d, 0x%x\n", this->getName(), surface->w, surface->h, target); 287 295 288 296 // build the MipMaps automaticaly 289 errorCode = gluBuild2DMipmaps(target, 290 GL_RGBA, 291 surface->w, 292 surface->h, 293 GL_RGBA, 294 GL_UNSIGNED_BYTE, 297 errorCode = gluBuild2DMipmaps(target, format, 298 surface->w, surface->h, 299 format, GL_UNSIGNED_BYTE, 295 300 surface->pixels 296 301 ); -
trunk/src/lib/graphics/importer/texture.h
r7221 r7727 43 43 44 44 protected: 45 46 45 bool setSurface(SDL_Surface* newSurface); 47 46 bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; }; 48 47 bool setTexture(GLuint texture) { this->texture = texture; }; 49 50 48 51 49 private:
Note: See TracChangeset
for help on using the changeset viewer.