Changeset 8363 in orxonox.OLD for trunk/src/lib/graphics/importer/texture.cc
- Timestamp:
- Jun 14, 2006, 10:37:08 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/texture.cc
r8316 r8363 37 37 */ 38 38 Uint32 alphaMask[] = { 39 40 41 42 43 };39 0xFF000000, 40 0x00FF0000, 41 0x0000FF00, 42 0x000000FF, 43 }; 44 44 45 45 Uint32 opaqueMask[] = { 46 47 48 49 50 };46 0x00FF0000, 47 0x0000FF00, 48 0x000000FF, 49 0xFF000000 50 }; 51 51 #else 52 52 /* 53 54 55 53 * On the LIL_ENDIAN architecture everything is fine and easy. The 24 54 * and 32bit bitmaps have the same masks. 55 */ 56 56 Uint32 alphaMask[] = { 57 58 59 60 61 };57 0x000000FF, 58 0x0000FF00, 59 0x00FF0000, 60 0xFF000000, 61 }; 62 62 63 63 Uint32 *opaqueMask = alphaMask; 64 65 64 #endif 66 65 67 TextureData::TextureData() 68 { 69 this->bAlpha = false; 70 this->texture = 0; 71 this->image = NULL; 72 } 73 74 75 /** 76 * @brief Destructor of a Texture 66 67 68 /** 69 * @brief creates an Empty Texture, 77 70 * 78 * Frees Data, and deletes the textures from GL 79 */ 80 TextureData::~TextureData() 81 { 82 if (this->texture != 0) 83 glDeleteTextures(1, &this->texture); 84 if (this->image != NULL) 85 SDL_FreeSurface(this->image); 86 } 87 88 89 /** 90 * @brief Loads an SDL_Surface. 91 */ 92 bool TextureData::loadSurface(SDL_Surface* surface, GLenum target) 93 { 94 if (Texture::getTextureEnableState()) 95 { 96 SDL_Surface* newSurf = Texture::prepareSurface(surface, this->bAlpha); 97 if (newSurf != NULL) 98 { 99 this->setSurface(newSurf); 100 this->setTexture(Texture::loadTexToGL(newSurf, target)); 101 return true; 102 } 103 } 104 return false; 105 } 106 107 108 109 /** 110 * @brief set the surface this Texture handles 111 * @param newSurface the new Surface to set as the image for this Texture. 71 * onto this Texture you can load non-empty textures with the = 72 * operator. 73 */ 74 Texture::Texture() 75 { 76 this->init(); 77 } 78 79 /** 80 * @brief Creates a Texture from another Texture (copy Constructor) 81 * @param texture the Texture to copy. 112 82 * 113 * This deletes the old version of the stored Texture, 114 * and sets the newly given Surface as current. 115 */ 116 bool TextureData::setSurface(SDL_Surface* newSurface) 117 { 118 if (this->image != NULL) 119 SDL_FreeSurface(this->image); 120 121 this->image = newSurface; 122 123 return (this->image != NULL); 124 } 125 126 127 128 bool TextureData::setTexture(GLuint texture) 129 { 130 // unload the old Texture. 131 if (this->texture != 0 && glIsTexture(this->getTexture())) 132 { 133 glDeleteTextures(1, &this->texture); 134 } 135 this->texture = texture; 136 return (texture != 0); 137 } 138 139 Texture::Texture() 140 { 141 this->init(); 142 } 143 144 83 * @note only the Data-Pointer will be shared. 84 */ 145 85 Texture::Texture(const Texture& texture) 146 : data(texture.data)86 : data(texture.data) 147 87 { 148 88 this->setClassID(CL_TEXTURE, "Texture"); … … 150 90 } 151 91 152 92 /** 93 * @brief Creates a new empty Texture with the below properties. 94 * @param target: the GL-Target. 95 * @param width: the Width of the Texture. 96 * @param height: The Hight of the Texture. 97 * @param channels: also known as BitsPerPixel. 98 * @param type the Type of Texture. 99 */ 153 100 Texture::Texture(GLenum target, unsigned int width, unsigned int height, unsigned int channels, GLenum type) 154 101 { 155 102 this->init(); 156 GLuint texture = 0; 157 Texture::generateTexture(texture, target); 158 159 glBindTexture(target, texture); 160 161 unsigned int* pixels = new unsigned int[width * height * channels]; 162 memset(pixels, 0, width * height * channels * sizeof(unsigned int)); 163 164 165 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 166 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 167 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 168 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 169 170 glTexImage2D(target, 0, channels, width, height, 0, type, GL_UNSIGNED_INT, pixels); 171 172 173 174 delete[] pixels; 175 176 this->data->setTexture(texture); 103 104 SDL_Surface * surface = SDL_CreateRGBSurface(SDL_HWSURFACE, width, height, channels, 105 alphaMask[0], alphaMask[1], alphaMask[2], alphaMask[3]); 106 107 if(surface != NULL) 108 { 109 this->data->loadSurface(surface, target); 110 SDL_FreeSurface(surface); 111 } 177 112 } 178 113 … … 218 153 */ 219 154 Texture::~Texture() 220 { 221 } 155 {} 222 156 223 157 … … 308 242 int pixelDepth = 24; 309 243 310 244 Uint32* mask = opaqueMask; 311 245 312 246 /* Save the alpha blending attributes */ … … 318 252 hasAlpha = true; 319 253 pixelDepth = 32; 320 254 mask = alphaMask; 321 255 } 322 256 … … 324 258 surface->w, surface->h, 325 259 pixelDepth, 326 260 mask[0], mask[1], mask[2], mask[3] ); 327 261 if ( retSurface == NULL ) 328 262 return NULL; … … 377 311 Texture::generateTexture(texture, target); 378 312 379 // glTexImage2D(target, 0, format,380 // surface->w, surface->h,381 // 0, format, GL_UNSIGNED_BYTE,382 // surface->pixels);383 384 /// glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);385 /// glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT);313 // glTexImage2D(target, 0, format, 314 // surface->w, surface->h, 315 // 0, format, GL_UNSIGNED_BYTE, 316 // surface->pixels); 317 318 /// glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT); 319 /// glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT); 386 320 387 321 /// TODO CHECK THIS BACK in
Note: See TracChangeset
for help on using the changeset viewer.