Changeset 5863 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Dec 1, 2005, 9:14:30 PM (19 years ago)
- Location:
- trunk/src/lib/graphics/importer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/texture.cc
r5860 r5863 45 45 } 46 46 47 47 48 /** 48 49 * Destructor of a Texture … … 57 58 SDL_FreeSurface(this->image); 58 59 } 60 59 61 60 62 /** … … 114 116 } 115 117 118 119 /** 120 * rebuilds the texture. 121 * reloads the Texture from Memory to OpenGL. 122 */ 116 123 bool Texture::rebuild() 117 124 { … … 128 135 this->setTexture(loadTexToGL(this->image)); 129 136 } 130 131 } 132 137 } 138 139 140 /** 141 * set the surface this Texture handles 142 * @param newSurface the new Surface to set as the image for this Texture. 143 * 144 * This deletes the old version of the stored Texture, 145 * and sets the newly given Surface as current. 146 */ 147 bool Texture::setSurface(SDL_Surface* newSurface) 148 { 149 if (this->image != NULL) 150 SDL_FreeSurface(this->image); 151 152 this->image = newSurface; 153 154 return (this->image != NULL); 155 } 156 157 158 bool Texture::texturesEnabled = true; 159 160 /** 161 * enables, disables textures 162 * @param texturesEnabled true if the textures should be enabled 163 */ 164 void Texture::setTextureEnableState(bool texturesEnabled) 165 { 166 Texture::texturesEnabled = texturesEnabled; 167 } 168 169 170 ////////////////////////////////////// 171 // UTILITY FUNCTIONALITY OF TEXTURE // 172 ////////////////////////////////////// 133 173 /** 134 174 * converts surface to a new SDL_Surface, that is loadable by openGL … … 148 188 hasAlpha = false; 149 189 retSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 150 surface->w, surface->h,151 32,190 surface->w, surface->h, 191 32, 152 192 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ 153 193 0x000000FF, … … 156 196 0xFF000000 157 197 #else 158 0xFF000000,198 0xFF000000, 159 199 0x00FF0000, 160 200 0x0000FF00, 161 201 0x000000FF 162 202 #endif 163 );203 ); 164 204 if ( retSurface == NULL ) 165 205 { … … 191 231 } 192 232 193 /** 194 * set the surface this Texture handles 195 * @param newSurface the new Surface to set as the image for this Texture. 196 * 197 * This deletes the old version of the stored Texture, 198 * and sets the newly given Surface as current. 199 */ 200 bool Texture::setSurface(SDL_Surface* newSurface) 201 { 202 if (this->image != NULL) 203 SDL_FreeSurface(this->image); 204 205 this->image = newSurface; 206 207 return (this->image != NULL); 208 } 209 210 211 bool Texture::texturesEnabled = true; 212 213 /** 214 * enables, disables textures 215 * @param texturesEnabled true if the textures should be enabled 216 */ 217 void Texture::setTextureEnableState(bool texturesEnabled) 218 { 219 Texture::texturesEnabled = texturesEnabled; 220 } 221 222 223 ////////////////////////////////////// 224 // UTILITY FUNCTIONALITY OF TEXTURE // 225 ////////////////////////////////////// 233 226 234 /** 227 235 * Loads a Texture to the openGL-environment. -
trunk/src/lib/graphics/importer/texture_sequence.cc
r5861 r5863 20 20 #include "debug.h" 21 21 #include "graphics_engine.h" 22 23 #include <stdarg.h>24 22 25 23 #ifdef HAVE_SDL_IMAGE_H … … 49 47 TextureSequence::~TextureSequence() 50 48 { 49 // delete all images 50 while(!this->images.empty()) 51 { 52 SDL_FreeSurface(this->images.back()); 53 this->images.pop_back(); 54 } 55 56 // delete all textures. 57 while(!this->textures.empty()) 58 { 59 if (glIsTexture(this->textures.back())) 60 glDeleteTextures(1, &this->textures.back()); 61 this->textures.pop_back(); 62 } 51 63 } 52 64 … … 57 69 bool TextureSequence::rebuild() 58 70 { 59 // if (this->texture != 0 && glIsTextureSequence(this->texture)) 60 // { 61 // glDeleteTextureSequences(1,&this->texture); 62 // this->texture = 0; 63 // } 64 // 65 // if (this->image != NULL) 66 // { 67 // PRINTF(3)("Reloading TextureSequence of %s '%s'\n", this->getClassName(), this->getName()); 68 // this->texture = loadTexToGL(this->image); 69 // } 71 PRINTF(3)("Reloading TextureSequence of %s '%s'\n", this->getClassName(), this->getName()); 70 72 73 for (unsigned int i = 0; i < this->textures.size(); i++) 74 { 75 if (glIsTexture(this->textures[i])) 76 { 77 glDeleteTextures(1, &this->textures[i]); 78 this->textures[i] = 0; 79 } 80 81 if (this->images[i] != NULL) 82 this->textures[i] = loadTexToGL(this->images[i]); 83 } 71 84 } 72 85 73 74 86 /** 87 * loads an image Series 88 * @param count how many images to load to the TextureSequence 89 * @param ... the names of the Images to load 90 * @returns true on success, false otherwise 91 */ 75 92 bool TextureSequence::loadImageSeries(unsigned int count, ...) 76 93 { … … 78 95 va_start(textureNameList, count); 79 96 80 this->loadImageSeries(count, textureNameList);97 return this->loadImageSeries(count, textureNameList); 81 98 } 82 99 100 /** 101 * loads an image Series 102 * @param count how many images to load to the TextureSequence 103 * @param textures the names of the Images to load 104 * @returns true on success, false otherwise 105 */ 83 106 bool TextureSequence::loadImageSeries(unsigned int count, va_list textures) 84 107 { 85 86 108 bool retVal = true; 109 for (unsigned int i = 0; i < count; i++) 110 { 111 if( !this->addFrame(va_arg(textures, char*))) 112 retVal = false; 113 } 114 return retVal; 87 115 } 88 116 … … 90 118 bool TextureSequence::addFrame(const char* imageName) 91 119 { 120 if (imageName == NULL) 121 return false; 92 122 123 SDL_Surface* addSurface = IMG_Load(imageName); 124 bool success = this->addFrame(addSurface); 125 delete addSurface; 93 126 127 return success; 94 128 } 95 129 96 130 /** 131 * adds a new Frame at the end of the Sequence. 132 * @param surface the Surface to add at the end of the Sequence. 133 */ 97 134 bool TextureSequence::addFrame(SDL_Surface* surface) 98 135 { 99 100 136 if (surface == NULL) 137 return false; 138 bool hasAlpha; 139 SDL_Surface* newSurf = this->prepareSurface(surface, hasAlpha); 140 if (newSurf != NULL) 141 { 142 this->images.push_back(newSurf); 143 this->textures.push_back(Texture::loadTexToGL(newSurf)); 144 } 145 this->setAlpha(hasAlpha); 101 146 } 102 103
Note: See TracChangeset
for help on using the changeset viewer.