Changeset 6979 in orxonox.OLD for trunk/src/lib/graphics
- Timestamp:
- Feb 2, 2006, 12:29:27 PM (19 years ago)
- Location:
- trunk/src/lib/graphics
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/effects/graphics_effect.cc
r6977 r6979 37 37 this->setClassID(CL_GRAPHICS_EFFECT, "GraphicsEffect"); 38 38 this->bActivated = false; 39 40 this->bActivated = GraphicsEngine::getInstance()->loadGraphicsEffect(this);41 39 } 42 40 … … 47 45 GraphicsEffect::~GraphicsEffect() 48 46 { 49 if( this->bActivated) 50 GraphicsEngine::getInstance()->unloadGraphicsEffect(this); 47 51 48 } 52 49 -
trunk/src/lib/graphics/graphics_engine.cc
r6978 r6979 46 46 #include "load_param.h" 47 47 #include "factory.h" 48 #include "class_list.h" 48 49 49 50 #ifdef __WIN32__ 50 #include "class_list.h"51 51 #include "static_model.h" 52 52 #endif … … 85 85 this->hwExtensions = NULL; 86 86 87 // initialize the TextEngine87 // initialize the Modules 88 88 TextEngine::getInstance(); 89 this->graphicsEffects = NULL; 90 89 91 } 90 92 … … 115 117 116 118 SDL_QuitSubSystem(SDL_INIT_VIDEO); 117 // if (this->screen != NULL)118 // SDL_FreeSurface(this->screen);119 // if (this->screen != NULL) 120 // SDL_FreeSurface(this->screen); 119 121 120 122 GraphicsEngine::singletonRef = NULL; … … 128 130 void GraphicsEngine::loadParams(const TiXmlElement* root) 129 131 { 130 LoadParamXML(root, "GraphicsEffect", this, GraphicsEngine, loadGraphicsEffect XML)131 132 LoadParamXML(root, "GraphicsEffect", this, GraphicsEngine, loadGraphicsEffects) 133 .describe("loads a graphics effect"); 132 134 } 133 135 … … 169 171 this->initVideo(atoi(resolution.getString(0)), atoi(resolution.getString(1)), 16); 170 172 171 // GraphicsEffect* fe = new FogEffect(NULL);172 // this->loadGraphicsEffect(fe);173 // fe->activate();174 // PRINTF(0)("--------------------------------------------------------------\n");173 // GraphicsEffect* fe = new FogEffect(NULL); 174 // this->loadGraphicsEffect(fe); 175 // fe->activate(); 176 // PRINTF(0)("--------------------------------------------------------------\n"); 175 177 176 178 //LenseFlare* ge = new LenseFlare(); … … 203 205 { 204 206 PRINTF(1)("could not initialize SDL Video\n"); 205 207 // return -1; 206 208 } 207 209 // initialize SDL_GL-settings … … 214 216 const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo (); 215 217 if( videoInfo == NULL) 216 217 218 219 218 { 219 PRINTF(1)("Failed getting Video Info :%s\n", SDL_GetError()); 220 SDL_Quit (); 221 } 220 222 if( videoInfo->hw_available) 221 223 this->videoFlags |= SDL_HWSURFACE; … … 226 228 VideoFlags |= SDL_HWACCEL; 227 229 */ 228 230 // setting up the Resolution 229 231 this->setResolution(resX, resY, bbp); 230 232 … … 293 295 const char* extensions = (const char*) glGetString(GL_EXTENSIONS); 294 296 295 // printf("%s %s %s\n %s", renderer, vendor, version, extensions);297 // printf("%s %s %s\n %s", renderer, vendor, version, extensions); 296 298 297 299 if (this->hwRenderer == NULL && renderer != NULL) … … 348 350 SDL_FreeSurface(screen); 349 351 if((this->screen = SDL_SetVideoMode(this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags | this->fullscreenFlag)) == NULL) 350 351 352 353 354 355 352 { 353 PRINTF(1)("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags, SDL_GetError()); 354 // SDL_Quit(); 355 // return -1; 356 } 357 glViewport(0, 0, width, height); // Reset The Current Viewport 356 358 357 359 #ifdef __WIN32__ 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 360 // REBUILDING TEXTURES (ON WINDOWS CONTEXT SWITCH) 361 const std::list<BaseObject*>* texList = ClassList::getList(CL_TEXTURE); 362 if (texList != NULL) 363 { 364 std::list<BaseObject*>::const_iterator reTex; 365 for (reTex = texList->begin(); reTex != texList->end(); reTex++) 366 dynamic_cast<Texture*>(*reTex)->rebuild(); 367 } 368 // REBUILDING MODELS 369 const std::list<BaseObject*>* modelList = ClassList::getList(CL_STATIC_MODEL); 370 if (texList != NULL) 371 { 372 std::list<BaseObject*>::const_iterator reModel; 373 for (reModel = modelList->begin(); reModel != modelList->end(); reModel++) 374 dynamic_cast<StaticModel*>(*reModel)->rebuild(); 375 } 374 376 #endif /* __WIN32__ */ 375 377 } … … 444 446 { 445 447 #if DEBUG < 3 446 447 448 449 448 if (steal) 449 SDL_WM_GrabInput(SDL_GRAB_ON); 450 else 451 SDL_WM_GrabInput(SDL_GRAB_OFF); 450 452 #endif 451 453 } … … 457 459 bool GraphicsEngine::isStealingEvents() 458 460 { 459 460 461 462 461 if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON) 462 return true; 463 else 464 return false; 463 465 }; 464 466 … … 539 541 540 542 /* Check is there are any modes available */ 541 if(this->videoModes == (SDL_Rect **)0){ 543 if(this->videoModes == (SDL_Rect **)0) 544 { 542 545 PRINTF(1)("No modes available!\n"); 543 546 exit(-1); … … 545 548 546 549 /* Check if our resolution is restricted */ 547 if(this->videoModes == (SDL_Rect **)-1){ 550 if(this->videoModes == (SDL_Rect **)-1) 551 { 548 552 PRINTF(2)("All resolutions available.\n"); 549 553 } 550 else{ 554 else 555 { 551 556 /* Print valid modes */ 552 557 PRINT(0)("Available Resoulution Modes are\n"); … … 592 597 593 598 #ifndef NO_TEXT 594 595 596 597 598 599 600 601 602 599 char tmpChar1[20]; 600 sprintf(tmpChar1, "Current: %4.0f", this->currentFPS); 601 this->geTextCFPS->setText(tmpChar1); 602 char tmpChar2[20]; 603 sprintf(tmpChar2, "Max: %4.0f", this->maxFPS); 604 this->geTextMaxFPS->setText(tmpChar2); 605 char tmpChar3[20]; 606 sprintf(tmpChar3, "Min: %4.0f", this->minFPS); 607 this->geTextMinFPS->setText(tmpChar3); 603 608 #endif /* NO_TEXT */ 604 609 … … 608 613 609 614 // tick the graphics effects 610 list<GraphicsEffect*>::iterator it; 611 for (it = this->graphicsEffects.begin(); it != this->graphicsEffects.end(); it++) 612 (*it)->tick(dt); 615 if (this->graphicsEffects != NULL || (this->graphicsEffects = ClassList::getList(CL_GRAPHICS_EFFECT)) != NULL) 616 { 617 std::list<BaseObject*>::const_iterator it; 618 for (it = this->graphicsEffects->begin(); it != this->graphicsEffects->end(); it++) 619 dynamic_cast<GraphicsEffect*>(*it)->tick(dt); 620 } 613 621 } 614 622 … … 625 633 Shader::restoreShader(); 626 634 627 //draw the graphics effects 628 list<GraphicsEffect*>::const_iterator it; 629 for (it = this->graphicsEffects.begin(); it != this->graphicsEffects.end(); it++) 630 (*it)->draw(); 635 if (this->graphicsEffects != NULL) 636 { 637 //draw the graphics effects 638 list<BaseObject*>::const_iterator it; 639 for (it = this->graphicsEffects->begin(); it != this->graphicsEffects->end(); it++) 640 dynamic_cast<GraphicsEffect*>(*it)->draw(); 641 } 631 642 } 632 643 … … 648 659 #ifndef NO_TEXT 649 660 if( display ) 650 {651 if (this->geTextCFPS == NULL)652 {653 this->geTextCFPS = new Text("fonts/arial_black.ttf", 15);654 this->geTextCFPS->setName("curFPS");655 this->geTextCFPS->setAlignment(TEXT_ALIGN_LEFT);656 this->geTextCFPS->setAbsCoor2D(5, 0);657 }658 if (this->geTextMaxFPS == NULL)659 {660 this->geTextMaxFPS = new Text("fonts/arial_black.ttf", 15);661 this->geTextMaxFPS->setName("MaxFPS");662 this->geTextMaxFPS->setAlignment(TEXT_ALIGN_LEFT);663 this->geTextMaxFPS->setAbsCoor2D(5, 20);664 }665 if (this->geTextMinFPS == NULL)666 {667 this->geTextMinFPS = new Text("fonts/arial_black.ttf", 15);668 this->geTextMinFPS->setName("MinFPS");669 this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT);670 this->geTextMinFPS->setAbsCoor2D(5, 40);671 }672 }673 else674 {675 delete this->geTextCFPS;676 this->geTextCFPS = NULL;677 delete this->geTextMaxFPS;678 this->geTextMaxFPS = NULL;679 delete this->geTextMinFPS;680 this->geTextMinFPS = NULL;681 }661 { 662 if (this->geTextCFPS == NULL) 663 { 664 this->geTextCFPS = new Text("fonts/arial_black.ttf", 15); 665 this->geTextCFPS->setName("curFPS"); 666 this->geTextCFPS->setAlignment(TEXT_ALIGN_LEFT); 667 this->geTextCFPS->setAbsCoor2D(5, 0); 668 } 669 if (this->geTextMaxFPS == NULL) 670 { 671 this->geTextMaxFPS = new Text("fonts/arial_black.ttf", 15); 672 this->geTextMaxFPS->setName("MaxFPS"); 673 this->geTextMaxFPS->setAlignment(TEXT_ALIGN_LEFT); 674 this->geTextMaxFPS->setAbsCoor2D(5, 20); 675 } 676 if (this->geTextMinFPS == NULL) 677 { 678 this->geTextMinFPS = new Text("fonts/arial_black.ttf", 15); 679 this->geTextMinFPS->setName("MinFPS"); 680 this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT); 681 this->geTextMinFPS->setAbsCoor2D(5, 40); 682 } 683 } 684 else 685 { 686 delete this->geTextCFPS; 687 this->geTextCFPS = NULL; 688 delete this->geTextMaxFPS; 689 this->geTextMaxFPS = NULL; 690 delete this->geTextMinFPS; 691 this->geTextMinFPS = NULL; 692 } 682 693 this->bDisplayFPS = display; 683 694 #else … … 695 706 switch (event.type) 696 707 { 697 case EV_VIDEO_RESIZE:708 case EV_VIDEO_RESIZE: 698 709 this->resolutionChanged(event.resize); 699 710 break; … … 705 716 * @param root The XML-element to load GraphicsEffects from 706 717 */ 707 void GraphicsEngine::loadGraphicsEffect XML(const TiXmlElement* root)718 void GraphicsEngine::loadGraphicsEffects(const TiXmlElement* root) 708 719 { 709 720 LOAD_PARAM_START_CYCLE(root, element); … … 714 725 LOAD_PARAM_END_CYCLE(element); 715 726 } 716 717 718 /**719 * loads a GraphicsEffect into the engine720 * @param effect the GraphicsEffect to add721 */722 bool GraphicsEngine::loadGraphicsEffect(GraphicsEffect* effect)723 {724 list<GraphicsEffect*>::iterator it;725 for (it = this->graphicsEffects.begin(); it != this->graphicsEffects.end(); it++)726 if( (*it) == effect)727 return false;728 729 this->graphicsEffects.push_back(effect);730 731 return true;732 }733 734 735 /**736 * unloads a GraphicsEffect from the engine737 * @param effect the GraphicsEffect to remove738 */739 bool GraphicsEngine::unloadGraphicsEffect(GraphicsEffect* effect)740 {741 list<GraphicsEffect*>::iterator it;742 for (it = this->graphicsEffects.begin(); it != this->graphicsEffects.end(); it++)743 {744 if( (*it) == effect)745 {746 this->graphicsEffects.erase(it);747 return true;748 }749 }750 751 return false;752 }753 -
trunk/src/lib/graphics/graphics_engine.h
r6815 r6979 86 86 void process(const Event &event); 87 87 88 void loadGraphicsEffectXML(const TiXmlElement* root); 89 bool loadGraphicsEffect(GraphicsEffect* effect); 90 bool unloadGraphicsEffect(GraphicsEffect* effect); 88 void loadGraphicsEffects(const TiXmlElement* root); 91 89 92 90 … … 134 132 float minFPS; //!< minimal frame rate we ever got since start. 135 133 136 std::list<GraphicsEffect*> graphicsEffects;//!< list of graphics effects134 const std::list<BaseObject*>* graphicsEffects; //!< list of graphics effects 137 135 138 136
Note: See TracChangeset
for help on using the changeset viewer.