Changeset 3344 in orxonox.OLD for orxonox/branches/parenting
- Timestamp:
- Jan 5, 2005, 5:50:07 PM (20 years ago)
- Location:
- orxonox/branches/parenting/src/importer
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/parenting/src/importer/material.cc
r3340 r3344 50 50 if (this->name) 51 51 delete []this->name; 52 if (this->diffuseTexture Set)53 glDeleteTextures (1, &this->diffuseTexture);52 if (this->diffuseTexture) 53 this->diffuseTexture; 54 54 if (this->nextMat) 55 55 delete this->nextMat; … … 89 89 this->setTransparency(0.0); 90 90 91 92 this->diffuseTexture = NULL; 93 this->ambientTexture = NULL; 94 this->specularTexture = NULL; 91 95 92 96 this->diffuseTextureSet = false; … … 145 149 146 150 if (this->diffuseTextureSet) 147 glBindTexture(GL_TEXTURE_2D, this->diffuseTexture );151 glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture()); 148 152 else 149 153 glBindTexture(GL_TEXTURE_2D, 0); … … 318 322 { 319 323 PRINTF(3)("setting Diffuse Map %s\n", dMap); 320 Texture* tmp= new Texture();321 this->diffuseTextureSet = tmp->loadImage(dMap, &this->diffuseTexture);324 diffuseTexture = new Texture(); 325 this->diffuseTextureSet = diffuseTexture->loadImage(dMap); 322 326 323 327 } -
orxonox/branches/parenting/src/importer/material.h
r3340 r3344 70 70 float transparency;//!< The transperency of the Material. 71 71 72 GLuintdiffuseTexture; //!< The diffuse texture of the Material.73 GLuintambientTexture; //!< The ambient texture of the Material.74 GLuintspecularTexture;//!< The specular texture of the Material.72 Texture* diffuseTexture; //!< The diffuse texture of the Material. 73 Texture* ambientTexture; //!< The ambient texture of the Material. 74 Texture* specularTexture;//!< The specular texture of the Material. 75 75 76 76 bool diffuseTextureSet; //!< Chekcs if the diffuse texture is Set. -
orxonox/branches/parenting/src/importer/texture.cc
r3343 r3344 113 113 } 114 114 115 116 117 /** 118 \brief Constructor for a Texture 119 */ 120 Texture::Texture(void) 121 { 122 this->pImage = new Image; 123 this->pImage->data = NULL; 124 this->texture = 0; 125 } 126 127 /** 128 \brief Destructor of a Texture 129 130 Frees Data, and deletes the textures from GL 131 */ 132 Texture::~Texture(void) 133 { 134 if (this->pImage->data) 135 delete []this->pImage->data; 136 delete pImage; 137 if (this->texture) 138 glDeleteTextures(1, &this->texture); 139 } 140 141 /** 142 \returns The Texture-identifier number. 143 */ 144 GLuint Texture::getTexture(void) 145 { 146 return this->texture; 147 } 115 148 116 149 /** … … 147 180 } 148 181 182 /** 183 \brief a Simple function that switches two char values 184 \param a The first value 185 \param b The second value 186 */ 149 187 inline void Texture::swap (unsigned char &a, unsigned char &b) 150 188 { … … 161 199 \param texture The Texture to apply it to. 162 200 */ 163 bool Texture::loadTexToGL (Image* pImage , GLuint* texture)201 bool Texture::loadTexToGL (Image* pImage) 164 202 { 165 203 PRINTF(2)("Loading texture to OpenGL-Environment.\n"); 166 glGenTextures(1, texture);167 glBindTexture(GL_TEXTURE_2D, *texture);204 glGenTextures(1, &this->texture); 205 glBindTexture(GL_TEXTURE_2D, this->texture); 168 206 /* not Working, and not needed. 169 207 glTexImage2D( GL_TEXTURE_2D, 0, 3, width, … … 179 217 180 218 #ifdef HAVE_SDL_SDL_IMAGE_H 181 bool Texture::loadImage(char* imageName , GLuint* texture)219 bool Texture::loadImage(char* imageName) 182 220 { 183 221 char* imgNameWithPath = searchTextureInPaths(imageName); … … 185 223 { 186 224 SDL_Surface* map; 187 Image* pImage = new Image;188 225 map=IMG_Load(imgNameWithPath); 189 226 if(!map) … … 209 246 swap( pImage->data[ (i * pImage->width * pImage->bpp) + j + k], pImage->data[ ( (pImage->height - i - 1) * pImage->width * pImage->bpp ) + j + k]); 210 247 211 this->loadTexToGL ( pImage, texture);248 this->loadTexToGL (this->pImage); 212 249 } 213 250 else … … 225 262 2. ToDO: Checks where to find the Image 226 263 */ 227 bool Texture::loadImage(char* imageName , GLuint* texture)264 bool Texture::loadImage(char* imageName) 228 265 { 229 266 char* imgNameWithPath = searchTextureInPaths(imageName); … … 233 270 { 234 271 PRINTF(3)("Requested bmp-image. Trying to Import.\n"); 235 return this->loadBMP(imgNameWithPath , texture);272 return this->loadBMP(imgNameWithPath); 236 273 } 237 274 … … 239 276 { 240 277 PRINTF(3)("Requested jpeg-image. Trying to Import\n"); 241 return this->loadJPG(imgNameWithPath , texture);278 return this->loadJPG(imgNameWithPath); 242 279 } 243 280 else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".tga", 4)) 244 281 { 245 282 PRINTF(3)("Requested tga-image. Trying to Import\n"); 246 return this->loadTGA(imgNameWithPath , texture);283 return this->loadTGA(imgNameWithPath); 247 284 } 248 285 else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".png", 4)) 249 286 { 250 287 PRINTF(3)("Requested png-image. Trying to Import\n"); 251 return this->loadPNG(imgNameWithPath , texture);288 return this->loadPNG(imgNameWithPath); 252 289 } 253 290 else … … 269 306 \param texture A pointer to the Texture which should be read to. 270 307 */ 271 bool Texture::loadBMP (char* bmpName, GLuint* texture) 272 { 273 Image* pImage = new Image; 308 bool Texture::loadBMP (char* bmpName) 309 { 274 310 FILE *file; 275 311 unsigned long size; // size of the image in bytes. … … 353 389 pImage->data[i+2] = temp; 354 390 } 355 this->loadTexToGL (pImage , texture);391 this->loadTexToGL (pImage); 356 392 357 393 … … 374 410 \param texture a reference to the Texture to write the image to 375 411 */ 376 bool Texture::loadJPG (char* jpgName , GLuint* texture)412 bool Texture::loadJPG (char* jpgName) 377 413 { 378 414 #ifdef HAVE_JPEGLIB_H … … 451 487 exit(0); 452 488 453 this->loadTexToGL (pImage , texture);489 this->loadTexToGL (pImage); 454 490 if (pImage) 455 491 { … … 474 510 \param texture a reference to the Texture to write the image to 475 511 */ 476 bool Texture::loadTGA(const char * tgaName , GLuint* texture)512 bool Texture::loadTGA(const char * tgaName) 477 513 { 478 514 typedef struct … … 505 541 if(memcmp(uTGAcompare, &tgaHeader, sizeof(TGAHeader)) == 0) 506 542 { 507 loadUncompressedTGA(tgaName, fTGA , texture);543 loadUncompressedTGA(tgaName, fTGA); 508 544 if (fTGA) 509 545 fclose (fTGA); … … 511 547 else if(memcmp(cTGAcompare, &tgaHeader, sizeof(TGAHeader)) == 0) 512 548 { 513 loadCompressedTGA(tgaName, fTGA , texture);549 loadCompressedTGA(tgaName, fTGA); 514 550 if (fTGA) 515 551 fclose (fTGA); … … 531 567 \param texture a reference to the Texture to write the image to 532 568 */ 533 bool Texture::loadUncompressedTGA(const char * filename, FILE * fTGA , GLuint* texture)569 bool Texture::loadUncompressedTGA(const char * filename, FILE * fTGA) 534 570 { 535 571 GLubyte header[6]; // First 6 Useful Bytes From The Header … … 542 578 GLuint Bpp; // Bits Per Pixel 543 579 544 Image* pImage = new Image;545 580 GLuint cswap; 546 581 if(fread(header, sizeof(header), 1, fTGA) == 0) … … 595 630 } 596 631 597 this->loadTexToGL (pImage , texture);632 this->loadTexToGL (pImage); 598 633 599 634 return true; … … 606 641 \param texture a reference to the Texture to write the image to 607 642 */ 608 bool Texture::loadCompressedTGA(const char * filename, FILE * fTGA , GLuint* texture)643 bool Texture::loadCompressedTGA(const char * filename, FILE * fTGA) 609 644 { 610 645 GLubyte header[6]; // First 6 Useful Bytes From The Header … … 617 652 GLuint Bpp; // Bits Per Pixel 618 653 619 Image* pImage = new Image;620 621 622 654 if(fread(header, sizeof(header), 1, fTGA) == 0) 623 655 { … … 778 810 while(currentpixel < pixelcount); // Loop while there are still pixels left 779 811 780 this->loadTexToGL (pImage , texture);812 this->loadTexToGL (pImage); 781 813 782 814 return true; … … 796 828 \param texture a reference to the Texture to write the image to 797 829 */ 798 bool Texture::loadPNG(const char* pngName , GLuint* texture)830 bool Texture::loadPNG(const char* pngName) 799 831 { 800 832 #ifdef HAVE_PNG_H 801 Image* pImage = new Image;802 833 803 834 FILE *PNG_file = fopen(pngName, "rb"); … … 912 943 } 913 944 */ 914 this->loadTexToGL (pImage , texture);945 this->loadTexToGL (pImage); 915 946 916 947 free(pImage->data); -
orxonox/branches/parenting/src/importer/texture.h
r3343 r3344 64 64 GLubyte *data; //!< The Image Data comes here! DANGER: uncompressed data. 65 65 }; 66 Image* pImage; 67 GLuint texture; 66 68 char* searchTextureInPaths(char* texName) const; 67 69 inline void swap(unsigned char &a, unsigned char &b); 68 70 public: 71 Texture(void); 72 ~Texture(void); 69 73 70 bool loadTexToGL (Image* pImage, GLuint* texture); 74 GLuint getTexture(void); 75 bool loadTexToGL (Image* pImage); 71 76 72 bool loadImage(char* imageName , GLuint* texture);77 bool loadImage(char* imageName); 73 78 #ifndef HAVE_SDL_SDL_IMAGE_H 74 79 75 bool loadBMP (char* bmpName , GLuint* texture);80 bool loadBMP (char* bmpName); 76 81 77 bool loadJPG (char* jpgName , GLuint* texture);82 bool loadJPG (char* jpgName); 78 83 79 84 /// TGA /// 80 85 81 bool loadTGA(const char * tgaName , GLuint* texture);82 bool loadUncompressedTGA(const char * filename, FILE * fTGA , GLuint* texture);83 bool loadCompressedTGA(const char * filename, FILE * fTGA , GLuint* texture);86 bool loadTGA(const char * tgaName); 87 bool loadUncompressedTGA(const char * filename, FILE * fTGA); 88 bool loadCompressedTGA(const char * filename, FILE * fTGA); 84 89 85 90 bool loadPNG(const char* pngName, GLuint* texture);
Note: See TracChangeset
for help on using the changeset viewer.