Changeset 3790 in orxonox.OLD for orxonox/trunk/src/lib
- Timestamp:
- Apr 13, 2005, 12:33:07 PM (20 years ago)
- Location:
- orxonox/trunk/src/lib
- Files:
-
- 1 deleted
- 9 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/graphics/graphics_engine.cc
r3622 r3790 167 167 168 168 169 /** 170 \brief entering 2D Mode 171 172 this is a GL-Projection-mode, that is orthogonal, for placing the font in fron of everything else 173 */ 174 void GraphicsEngine::enter2DMode(void) 175 { 176 SDL_Surface *screen = SDL_GetVideoSurface(); 177 178 /* Note, there may be other things you need to change, 179 depending on how you have your OpenGL state set up. 180 */ 181 glPushAttrib(GL_ENABLE_BIT); 182 glDisable(GL_DEPTH_TEST); 183 glDisable(GL_CULL_FACE); 184 glDisable(GL_LIGHTING); // will be set back when leaving 2D-mode 185 glEnable(GL_TEXTURE_2D); 186 187 /* This allows alpha blending of 2D textures with the scene */ 188 glEnable(GL_BLEND); 189 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 190 191 glViewport(0, 0, screen->w, screen->h); 192 193 glMatrixMode(GL_PROJECTION); 194 glPushMatrix(); 195 glLoadIdentity(); 196 197 glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0); 198 199 glMatrixMode(GL_MODELVIEW); 200 glPushMatrix(); 201 glLoadIdentity(); 202 203 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 204 } 205 206 /** 207 \brief leaves the 2DMode again also \see Font::enter2DMode(void) 208 */ 209 void GraphicsEngine::leave2DMode(void) 210 { 211 glMatrixMode(GL_MODELVIEW); 212 glPopMatrix(); 213 214 glMatrixMode(GL_PROJECTION); 215 glPopMatrix(); 216 217 glPopAttrib(); 218 } 169 219 170 220 -
orxonox/trunk/src/lib/graphics/graphics_engine.h
r3619 r3790 26 26 int setGLattribs(void); 27 27 int setResolution(int width, int height, int bpp); 28 /** \returns the x resolution */ 29 inline int getResolutionX(void) {return this->resolutionX;} 30 /** \returns the y resolution */ 31 inline int getResolutionY(void) {return this->resolutionY;} 32 /** \returns the Bits Per Pixel */ 33 inline int getbbp(void) {return this->bitsPerPixel;} 28 34 int resolutionChanged(SDL_ResizeEvent* resizeInfo); 29 35 void listModes(void); 30 36 31 37 static bool texturesEnabled; 38 39 static void enter2DMode(void); 40 static void leave2DMode(void); 32 41 33 42 private: -
orxonox/trunk/src/lib/graphics/importer/material.cc
r3672 r3790 30 30 using namespace std; 31 31 32 33 /**34 \brief creates a default Material with no Name35 normally you call this to create a material List (for an obj-file) and then append with addMaterial()36 */37 Material::Material()38 {39 this->init();40 41 this->setName ("");42 }43 44 32 /** 45 33 \brief creates a Material. … … 48 36 Material::Material (char* mtlName) 49 37 { 50 this->init(); 51 52 this->setName (mtlName); 38 PRINTF(4)("initializing new Material.\n"); 39 this->nextMat = NULL; 40 this->name =""; 41 this->setIllum(3); 42 this->setDiffuse(0,0,0); 43 this->setAmbient(0,0,0); 44 this->setSpecular(.5,.5,.5); 45 this->setShininess(2.0); 46 this->setTransparency(1.0); 47 48 49 this->diffuseTexture = NULL; 50 this->ambientTexture = NULL; 51 this->specularTexture = NULL; 52 53 this->diffuseTextureSet = false; 54 this->ambientTextureSet = false; 55 this->specularTextureSet = false; 56 57 if (mtlName) 58 this->setName (mtlName); 59 else 60 this->setName(""); 53 61 } 54 62 … … 86 94 87 95 /** 88 \brief initializes a new Material with its default Values89 */90 void Material::init(void)91 {92 PRINTF(4)("initializing new Material.\n");93 this->nextMat = NULL;94 this->name ="";95 this->setIllum(3);96 this->setDiffuse(0,0,0);97 this->setAmbient(0,0,0);98 this->setSpecular(.5,.5,.5);99 this->setShininess(2.0);100 this->setTransparency(0.0);101 102 103 this->diffuseTexture = NULL;104 this->ambientTexture = NULL;105 this->specularTexture = NULL;106 107 this->diffuseTextureSet = false;108 this->ambientTextureSet = false;109 this->specularTextureSet = false;110 }111 112 /**113 96 \brief Search for a Material called mtlName 114 97 \param mtlName the Name of the Material to search for … … 151 134 glMaterialf(GL_FRONT, GL_SHININESS, this->shininess); 152 135 136 // setting the transparency 137 if (this->transparency == 1.0) 138 { 139 glDisable(GL_BLEND); 140 } 141 else 142 { 143 glEnable(GL_BLEND); 144 glColor4f(1.0f, 1.0f, 1.0f, this->transparency); 145 glBlendFunc(GL_SRC_ALPHA, GL_ONE); 146 } 147 153 148 // setting illumination Model 154 149 if (this->illumModel == 1) //! \todo make this work, if no vertex-normals are read. -
orxonox/trunk/src/lib/graphics/importer/material.h
r3590 r3790 22 22 { 23 23 public: 24 Material (); 25 Material (char* mtlName); 24 Material (char* mtlName = ""); 26 25 Material* addMaterial(char* mtlName); 27 26 ~Material (); 28 void init(void);29 27 30 28 Material* search(char* mtlName); -
orxonox/trunk/src/lib/graphics/importer/texture.cc
r3660 r3790 98 98 } 99 99 100 #ifdef HAVE_SDL_ SDL_IMAGE_H100 #ifdef HAVE_SDL_IMAGE_H 101 101 bool Texture::loadImage(const char* imageName) 102 102 { … … 118 118 pImage->format = GL_RGB; 119 119 else if (pImage->bpp == 4) 120 pImage->format = GL_RGBA; 121 120 { 121 pImage->format = GL_RGBA; 122 SDL_SetAlpha(this->map, 0, 0); 123 } 124 122 125 if( !IMG_isPNG(SDL_RWFromFile(imageName, "rb")) && !IMG_isJPG(SDL_RWFromFile(imageName, "rb"))) 123 126 for (int i=0;i<map->h * map->w *3;i+=3) … … 146 149 147 150 148 #else /* HAVE_SDL_ SDL_IMAGE_H */151 #else /* HAVE_SDL_IMAGE_H */ 149 152 /** 150 153 \brief Makes the Programm ready to Read-in a texture-File … … 832 835 833 836 } 834 #endif /* HAVE_SDL_ SDL_IMAGE_H */837 #endif /* HAVE_SDL_IMAGE_H */ -
orxonox/trunk/src/lib/graphics/importer/texture.h
r3660 r3790 14 14 #include "debug.h" 15 15 16 #ifdef HAVE_SDL_ SDL_IMAGE_H17 #include <SDL /SDL_image.h>16 #ifdef HAVE_SDL_IMAGE_H 17 #include <SDL_image.h> 18 18 #else 19 19 // IMAGE LIBS // … … 26 26 #include <png.h> 27 27 #endif /* HAVE_PNG_H */ 28 #endif /* HAVE_SDL_ SDL_IMAGE_H */28 #endif /* HAVE_SDL_IMAGE_H */ 29 29 30 30 //! A Class, that reads in Textures from different fileformats. … … 57 57 58 58 bool loadImage(const char* imageName); 59 #ifndef HAVE_SDL_ SDL_IMAGE_H59 #ifndef HAVE_SDL_IMAGE_H 60 60 61 61 bool loadBMP (char* bmpName); … … 74 74 75 75 }; 76 77 78 79 76 #endif /* _TEXTURE_H */ -
orxonox/trunk/src/lib/util/list.h
r3669 r3790 107 107 void destroy(); 108 108 T* firstElement(); 109 T* lastElement(); 109 110 bool isEmpty(); 110 111 int getSize(); … … 217 218 } 218 219 220 template<class T> 221 T* tList<T>::lastElement() 222 { 223 return this->last->curr; 224 } 225 219 226 220 227 template<class T> -
orxonox/trunk/src/lib/util/resource_manager.cc
r3677 r3790 22 22 #include "primitive_model.h" 23 23 #include "texture.h" 24 #include "text_engine.h" 24 25 25 26 #include "list.h" … … 141 142 \returns a pointer to a desired Resource. 142 143 */ 143 void* ResourceManager::load(const char* fileName, ResourcePriority prio )144 void* ResourceManager::load(const char* fileName, ResourcePriority prio, void* param1, void* param2, void* param3) 144 145 { 145 146 ResourceType tmpType; … … 158 159 !strcmp(fileName, "cone")) 159 160 tmpType = PRIM; 161 else if (!strncmp(fileName+(strlen(fileName)-4), ".ttf", 4)) 162 tmpType = TTF; 160 163 else 161 164 tmpType = IMAGE; 162 165 163 return this->load(fileName, tmpType, prio );166 return this->load(fileName, tmpType, prio, param1, param2, param3); 164 167 } 165 168 … … 171 174 \returns a pointer to a desired Resource. 172 175 */ 173 void* ResourceManager::load(const char* fileName, ResourceType type, ResourcePriority prio )176 void* ResourceManager::load(const char* fileName, ResourceType type, ResourcePriority prio, void* param1, void* param2, void* param3) 174 177 { 175 178 // searching if the resource was loaded before. 176 Resource* tmpResource = this->locateResourceBy Name(fileName);179 Resource* tmpResource = this->locateResourceByInfo(fileName, type, param1, param2,param3); 177 180 if (tmpResource) // if the resource was not loaded before. 178 181 { … … 201 204 { 202 205 case OBJ: 206 if (param1) 207 tmpResource->modelSize = *(float*)param1; 208 else 209 tmpResource->modelSize = 1.0; 210 203 211 if(isFile(fullName)) 204 tmpResource->pointer = new OBJModel(fullName );212 tmpResource->pointer = new OBJModel(fullName, tmpResource->modelSize); 205 213 else 206 214 { 207 215 PRINTF(2)("Sorry, %s does not exist. Loading a cube-Model instead\n", fullName); 208 tmpResource->pointer = ResourceManager::load("cube", PRIM );216 tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, &tmpResource->modelSize); 209 217 } 210 218 break; 211 219 case PRIM: 220 if (param1) 221 tmpResource->modelSize = *(float*)param1; 222 else 223 tmpResource->modelSize = 1.0; 224 212 225 if (!strcmp(tmpResource->name, "cube")) 213 tmpResource->pointer = new PrimitiveModel(CUBE );226 tmpResource->pointer = new PrimitiveModel(CUBE, tmpResource->modelSize); 214 227 else if (!strcmp(tmpResource->name, "sphere")) 215 tmpResource->pointer = new PrimitiveModel(SPHERE );228 tmpResource->pointer = new PrimitiveModel(SPHERE, tmpResource->modelSize); 216 229 else if (!strcmp(tmpResource->name, "plane")) 217 tmpResource->pointer = new PrimitiveModel(PLANE );230 tmpResource->pointer = new PrimitiveModel(PLANE, tmpResource->modelSize); 218 231 else if (!strcmp(tmpResource->name, "cylinder")) 219 tmpResource->pointer = new PrimitiveModel(CYLINDER );232 tmpResource->pointer = new PrimitiveModel(CYLINDER, tmpResource->modelSize); 220 233 else if (!strcmp(tmpResource->name, "cone")) 221 tmpResource->pointer = new PrimitiveModel(CONE); 234 tmpResource->pointer = new PrimitiveModel(CONE, tmpResource->modelSize); 235 break; 236 case TTF: 237 if (param1) 238 tmpResource->ttfSize = *(int*)param1; 239 else 240 tmpResource->ttfSize = FONT_DEFAULT_SIZE; 241 if (param2) 242 { 243 Vector* tmpVec = (Vector*)param2; 244 tmpResource->ttfColorR = (int)tmpVec->x; 245 tmpResource->ttfColorG = (int)tmpVec->y; 246 tmpResource->ttfColorB = (int)tmpVec->z; 247 } 248 else 249 { 250 tmpResource->ttfColorR = FONT_DEFAULT_COLOR_R; 251 tmpResource->ttfColorG = FONT_DEFAULT_COLOR_G; 252 tmpResource->ttfColorB = FONT_DEFAULT_COLOR_B; 253 } 254 255 if(isFile(fullName)) 256 tmpResource->pointer = new Font(fullName, 257 tmpResource->ttfSize, 258 tmpResource->ttfColorR, 259 tmpResource->ttfColorG, 260 tmpResource->ttfColorB); 261 else 262 PRINTF(2)("Sorry, %s does not exist. Not loading Font\n", fullName); 222 263 break; 223 264 case IMAGE: … … 259 300 delete []fullName; 260 301 } 261 262 return tmpResource->pointer; 302 if (tmpResource->pointer) 303 return tmpResource->pointer; 304 else 305 { 306 PRINTF(2)("Resource %s could not be loaded\n", fileName); 307 delete tmpResource; 308 return NULL; 309 } 263 310 } 264 311 … … 299 346 case IMAGE: 300 347 delete (Texture*)resource->pointer; 348 break; 349 case TTF: 350 delete (Font*)resource->pointer; 301 351 break; 302 352 default: … … 342 392 343 393 /** 344 \brief Searches for a Resource by Name394 \brief Searches for a Resource by some information 345 395 \param fileName The name to look for 346 396 \returns a Pointer to the Resource if found, NULL otherwise. 347 397 */ 348 Resource* ResourceManager::locateResourceBy Name(const char* fileName)398 Resource* ResourceManager::locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3) 349 399 { 350 400 // Resource* enumRes = resourceList->enumerate(); … … 353 403 while (enumRes) 354 404 { 355 if (!strcmp(fileName, enumRes->name)) 356 { 357 delete iterator; 358 return enumRes; 405 if (enumRes->type == type && !strcmp(fileName, enumRes->name)) 406 { 407 bool match = false; 408 bool subMatch = false; 409 switch (type) 410 { 411 case PRIM: 412 case OBJ: 413 if (!param1) 414 { 415 if (enumRes->modelSize == 1.0) 416 match = true; 417 } 418 else if (enumRes->modelSize == *(float*)param1) 419 match = true; 420 break; 421 case TTF: 422 if (!param1) 423 { 424 if (enumRes->ttfSize == FONT_DEFAULT_SIZE) 425 subMatch = true; 426 } 427 else if (enumRes->modelSize =- *(int*)param1) 428 subMatch = true; 429 if(subMatch) 430 { 431 Vector* tmpVec = (Vector*)param2; 432 if (!param2) 433 { 434 if(enumRes->ttfColorR == FONT_DEFAULT_COLOR_R && 435 enumRes->ttfColorG == FONT_DEFAULT_COLOR_G && 436 enumRes->ttfColorB == FONT_DEFAULT_COLOR_B ) 437 match = true; 438 } 439 else if (enumRes->ttfColorR == (int)tmpVec->x && 440 enumRes->ttfColorG == (int)tmpVec->y && 441 enumRes->ttfColorB == (int)tmpVec->z ) 442 match = true; 443 } 444 445 break; 446 default: 447 match = true; 448 break; 449 } 450 if (match) 451 { 452 delete iterator; 453 return enumRes; 454 } 359 455 } 360 456 enumRes = iterator->nextElement(); … … 396 492 struct stat status; 397 493 stat(directoryName, &status); 398 if (status.st_mode & (S_IFDIR | S_IFLNK)) 494 if (status.st_mode & (S_IFDIR 495 #ifndef __WIN32__ 496 | S_IFLNK 497 #endif 498 )) 399 499 return true; 400 500 else … … 411 511 struct stat status; 412 512 stat(fileName, &status); 413 if (status.st_mode & (S_IFREG | S_IFLNK)) 513 if (status.st_mode & (S_IFREG 514 #ifndef __WIN32__ 515 | S_IFLNK 516 #endif 517 )) 414 518 return true; 415 519 else -
orxonox/trunk/src/lib/util/resource_manager.h
r3676 r3790 19 19 20 20 //! An eumerator for different fileTypes the resourceManager supports \todo WAV, MP3, OGG support 21 enum ResourceType {OBJ, PRIM, WAV, MP3, OGG, IMAGE};21 enum ResourceType {OBJ, PRIM, WAV, MP3, OGG, TTF, IMAGE}; 22 22 //! An enumerator for different UNLOAD-types. 23 23 /** … … 33 33 { 34 34 void* pointer; //!< Pointer to the Resource. 35 int count; //!< How many times this Resource has been loaded. 35 36 36 37 char* name; //!< Name of the Resource. 37 38 ResourceType type; //!< ResourceType of this Resource. 38 39 ResourcePriority prio; //!< The Priority of this resource. (This will only be increased) 39 int count; //!< How many times this Resource has been loaded. 40 41 // more specific 42 float modelSize; 43 unsigned int ttfSize; 44 unsigned char ttfColorR; 45 unsigned char ttfColorG; 46 unsigned char ttfColorB; 40 47 }; 41 48 … … 49 56 50 57 It does it by looking, if a desired file has already been loaded. 58 59 \todo loading also dependant by parameters. 51 60 */ 52 61 class ResourceManager : public BaseObject … … 58 67 bool setDataDir(char* dataDir); 59 68 bool addImageDir(char* imageDir); 60 void* load(const char* fileName, ResourcePriority prio = RP_NO); 61 void* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO); 69 void* load(const char* fileName, ResourcePriority prio = RP_NO, 70 void* param1 = NULL, void* param2 = NULL, void* param3 = NULL); 71 void* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO, 72 void* param1 = NULL, void* param2 = NULL, void* param3 = NULL); 62 73 bool unload(void* pointer, ResourcePriority prio = RP_NO); 63 74 bool unload(Resource* resource, ResourcePriority = RP_NO); … … 74 85 75 86 76 Resource* locateResourceBy Name(const char* fileName);87 Resource* locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3); 77 88 Resource* locateResourceByPointer(const void* pointer); 78 89
Note: See TracChangeset
for help on using the changeset viewer.