Changeset 3127 in orxonox.OLD for orxonox/branches/images/importer
- Timestamp:
- Dec 7, 2004, 8:02:05 PM (20 years ago)
- Location:
- orxonox/branches/images/importer
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/images/importer/framework.cc
r3122 r3127 1 1 #include "framework.h" 2 2 3 int verbose = 1;3 int verbose = 4; 4 4 5 5 void DrawGLScene() … … 43 43 // Create a new OpenGL window with the title "Cone3D Basecode" at 44 44 // 640x480x32, fullscreen and check for errors along the way 45 if(wHandler.CreateGLWindow("Whandler Basecode", 640, 480, 32, FALSE) == FALSE)45 if(wHandler.CreateGLWindow("Whandler Basecode", 800, 600, 32, FALSE) == FALSE) 46 46 { 47 47 // If an error is found, display a message, kill the GL and SDL screens (if they were created) and exit -
orxonox/branches/images/importer/material.cc
r3120 r3127 20 20 #include "material.h" 21 21 22 // headers only for PathList 23 #include <unistd.h> 24 #include <sys/types.h> 25 #include <sys/stat.h> 26 #include <stdlib.h> 27 #include <fstream> 28 29 using namespace std; 30 31 32 PathList::PathList() 33 { 34 pathName = NULL; 35 next = NULL; 36 } 37 PathList::PathList(char* pName) 38 { 39 pathName = new char [strlen(pName)+1]; 40 strcpy (pathName, pName); 41 next = NULL; 42 } 43 44 PathList::~PathList() 45 { 46 if (pathName) 47 delete []pathName; 48 if (next) 49 delete next; 50 } 51 52 void PathList::addPath (char* pName) 53 { 54 if (pName[0] == '\0') 55 { 56 if (verbose >=3) 57 printf("not Adding empty Path to the List.\n"); 58 return; 59 } 60 61 if (access (pName, F_OK) == 0) 62 { 63 struct stat status; 64 stat(pName, &status); 65 if (status.st_mode & S_IFDIR) 66 { 67 if (verbose >=2) 68 printf ("Adding Path %s to the PathList.\n", pName); 69 PathList* tmpPathList = this; 70 while (tmpPathList->next) 71 tmpPathList = tmpPathList->next; 72 tmpPathList->next = new PathList(pName); 73 } 74 else 75 if (verbose >=1) 76 printf ("You tried to add non-folder %s to a PathList.\n", pName); 77 } 78 else 79 if (verbose >=1) 80 printf ("You tried to add non-existing folder %s to a PathList.\n", pName); 81 } 22 82 23 83 /** … … 67 127 if (verbose >=2) 68 128 printf ("adding Material %s.\n", mtlName); 69 Material* newMat = new Material(mtlName); 70 Material* tmpMat = this; 129 Material* tmpMat = this; 71 130 while (tmpMat->nextMat != NULL) 72 131 { 73 132 tmpMat = tmpMat->nextMat; 74 133 } 75 tmpMat->nextMat = new Mat;76 return newMat;134 tmpMat->nextMat = new Material(mtlName); 135 return tmpMat->nextMat; 77 136 78 137 } … … 86 145 printf ("initializing new Material.\n"); 87 146 nextMat = NULL; 88 147 name =""; 89 148 setIllum(1); 90 149 setDiffuse(0,0,0); … … 94 153 setTransparency(0.0); 95 154 155 if (!pathList) 156 pathList = new PathList(""); 157 158 96 159 diffuseTextureSet = false; 97 160 ambientTextureSet = false; … … 100 163 101 164 } 165 166 PathList *Material::pathList = NULL; 102 167 103 168 /** … … 166 231 void Material::setName (char* mtlName) 167 232 { 168 if (verbose >= 3)169 printf("setting Material Name to %s.\n", mtlName);170 233 name = new char [strlen(mtlName)+1]; 171 234 strcpy(name, mtlName); 235 if (verbose >= 3) 236 printf("setting Material Name to %s.\n", name); 237 172 238 // printf ("adding new Material: %s, %p\n", this->getName(), this); 173 239 … … 188 254 { 189 255 if (verbose >= 3) 190 printf("setting illumModel of Material %s to %i ", name, illum);256 printf("setting illumModel of Material %s to %i\n", name, illum); 191 257 illumModel = illum; 192 258 // printf ("setting illumModel to: %i\n", illumModel); … … 317 383 } 318 384 385 void Material::addTexturePath(char* pathName) 386 { 387 pathList->addPath (pathName); 388 } 389 char* Material::searchTextureInPaths(char* texName) const 390 { 391 char* tmpName = NULL; 392 PathList* pList = pathList; 393 while (pList) 394 { 395 if (pList->pathName) 396 { 397 tmpName = new char [strlen(pList->pathName)+strlen(texName)+1]; 398 strcpy(tmpName, pList->pathName); 399 } 400 else 401 { 402 tmpName = new char [strlen(texName)+1]; 403 tmpName[0]='\0'; 404 } 405 strcat(tmpName, texName); 406 printf("%s\n", tmpName); 407 if (access (tmpName, F_OK) == 0) 408 return tmpName; 409 410 if (tmpName) 411 delete []tmpName; 412 tmpName = NULL; 413 pList = pList->next; 414 } 415 return NULL; 416 } 417 418 319 419 // MAPPING // 320 420 … … 364 464 bool Material::loadTexToGL (Image* pImage, GLuint* texture) 365 465 { 466 if (verbose >=3) 467 printf ("Loading texture to OpenGL-Environment.\n"); 366 468 glGenTextures(1, texture); 367 469 glBindTexture(GL_TEXTURE_2D, *texture); … … 381 483 bool Material::loadImage(char* imageName, GLuint* texture) 382 484 { 383 SDL_Surface* map; 384 Image* pImage = new Image; 385 map=IMG_Load(imageName); 386 if(!map) 387 { 388 printf("IMG_Load: %s\n", IMG_GetError()); 389 return false; 390 } 391 pImage->height = map->h; 392 pImage->width = map->w; 393 pImage->data = (GLubyte*)map->pixels; 394 if( !IMG_isPNG(SDL_RWFromFile(imageName, "rb")) && !IMG_isJPG(SDL_RWFromFile(imageName, "rb"))) 395 for (int i=0;i<map->h * map->w *3;i+=3) 396 { 397 GLuint temp = pImage->data[i]; 398 pImage->data[i] = pImage->data[i+2]; 399 pImage->data[i+2] = temp; 400 } 401 loadTexToGL (pImage, texture); 402 485 char* imgNameWithPath= searchTextureInPaths(imageName); 486 if (imgNameWithPath) 487 { 488 SDL_Surface* map; 489 Image* pImage = new Image; 490 map=IMG_Load(imgNameWithPath); 491 if(!map) 492 { 493 printf("IMG_Load: %s\n", IMG_GetError()); 494 return false; 495 } 496 pImage->height = map->h; 497 pImage->width = map->w; 498 pImage->data = (GLubyte*)map->pixels; 499 if( !IMG_isPNG(SDL_RWFromFile(imgNameWithPath, "rb")) && !IMG_isJPG(SDL_RWFromFile(imgNameWithPath, "rb"))) 500 for (int i=0;i<map->h * map->w *3;i+=3) 501 { 502 GLuint temp = pImage->data[i]; 503 pImage->data[i] = pImage->data[i+2]; 504 pImage->data[i+2] = temp; 505 } 506 loadTexToGL (pImage, texture); 507 } 508 else 509 { 510 if (verbose >=2) 511 printf ("Image not Found: %s\n", imageName); 512 return false; 513 } 403 514 } 404 515 #else -
orxonox/branches/images/importer/material.h
r3110 r3127 12 12 #include <GL/glu.h> 13 13 #include <SDL/SDL.h> 14 #include <stdlib.h>15 #include <fstream>16 14 17 15 #if HAVE_CONFIG_H … … 32 30 #endif /* HAVE_PNG_H */ 33 31 #endif /* HAVE_SDL_SDL_IMAGE_H */ 32 33 class PathList 34 { 35 public: 36 PathList(); 37 PathList(char* pName); 38 39 ~PathList(); 40 void addPath (char* pName); 41 char* pathName; 42 PathList* next; 43 }; 44 34 45 35 46 //! Class to handle Materials. … … 62 73 63 74 64 65 66 // MAPPING // 75 76 void addTexturePath(char* pathName); 77 char* searchTextureInPaths(char* texName) const; 78 // MAPPING // 67 79 void setDiffuseMap(char* dMap); 68 80 void setAmbientMap(char* aMap); 69 81 void setSpecularMap(char* sMap); 70 82 void setBump(char* bump); 71 72 83 73 84 private: … … 91 102 float transparency; 92 103 104 static PathList* pathList; 105 93 106 GLuint diffuseTexture; 94 107 GLuint ambientTexture; -
orxonox/branches/images/importer/object.cc
r3122 r3127 353 353 if (verbose >=2) 354 354 if (strlen(objPath)> 0) 355 printf("Resolved file %s to folder: %s.\n", name, objPath); 355 { 356 printf("Resolved file %s to folder: %s.\n", name, objPath); 357 } 356 358 else 357 359 printf("Resolved file %s.\n", name); 358 360 361 if (material) 362 material->addTexturePath(objPath); 359 363 objFileName = new char[strlen(name)+1]; 360 364 strcpy (objFileName, name);
Note: See TracChangeset
for help on using the changeset viewer.