$search
00001 #include "initialization.h" 00002 00003 #include <OGRE/OgreRoot.h> 00004 #include <OGRE/OgreRenderSystem.h> 00005 #include <OGRE/OgreLogManager.h> 00006 00007 #include <exception> 00008 #include <stdexcept> 00009 00010 #include <ros/package.h> 00011 00012 namespace ogre_tools 00013 { 00014 void initializeOgre(bool enable_ogre_log) 00015 { 00016 try 00017 { 00018 Ogre::LogManager* log_manager = new Ogre::LogManager(); 00019 log_manager->createLog( "Ogre.log", false, false, !enable_ogre_log ); 00020 00021 std::string plugin_prefix; 00022 #ifdef OGRE_PLUGIN_PATH 00023 plugin_prefix = OGRE_PLUGIN_PATH + std::string("/"); 00024 #endif 00025 00026 Ogre::Root* root = new Ogre::Root(); 00027 root->loadPlugin( plugin_prefix + "RenderSystem_GL" ); 00028 root->loadPlugin( plugin_prefix + "Plugin_OctreeSceneManager" ); 00029 root->loadPlugin( plugin_prefix + "Plugin_ParticleFX" ); 00030 root->loadPlugin( plugin_prefix + "Plugin_CgProgramManager" ); 00031 00032 // Taken from gazebo 00033 Ogre::RenderSystem* render_system = NULL; 00034 #if OGRE_VERSION_MAJOR >=1 && OGRE_VERSION_MINOR >= 7 00035 Ogre::RenderSystemList rsList = root->getAvailableRenderers(); 00036 Ogre::RenderSystemList::iterator renderIt = rsList.begin(); 00037 Ogre::RenderSystemList::iterator renderEnd = rsList.end(); 00038 #else 00039 Ogre::RenderSystemList* rsList = root->getAvailableRenderers(); 00040 Ogre::RenderSystemList::iterator renderIt = rsList->begin(); 00041 Ogre::RenderSystemList::iterator renderEnd = rsList->end(); 00042 #endif 00043 for ( ; renderIt != renderEnd; ++renderIt ) 00044 { 00045 render_system = *renderIt; 00046 00047 if ( render_system->getName() == "OpenGL Rendering Subsystem" ) 00048 { 00049 break; 00050 } 00051 } 00052 00053 if ( render_system == NULL ) 00054 { 00055 throw std::runtime_error( "Could not find the opengl rendering subsystem!\n" ); 00056 } 00057 00058 render_system->setConfigOption("Full Screen","No"); 00059 render_system->setConfigOption("FSAA","2"); 00060 render_system->setConfigOption("RTT Preferred Mode", "FBO"); 00061 00062 root->setRenderSystem( render_system ); 00063 00064 root->initialise( false ); 00065 00066 std::string ogre_tools_path = ros::package::getPath(ROS_PACKAGE_NAME); 00067 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( ogre_tools_path + "/media", "FileSystem", ROS_PACKAGE_NAME ); 00068 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( ogre_tools_path + "/media/fonts", "FileSystem", ROS_PACKAGE_NAME ); 00069 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( ogre_tools_path + "/media/models", "FileSystem", ROS_PACKAGE_NAME ); 00070 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( ogre_tools_path + "/media/materials", "FileSystem", ROS_PACKAGE_NAME ); 00071 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( ogre_tools_path + "/media/materials/scripts", "FileSystem", ROS_PACKAGE_NAME ); 00072 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( ogre_tools_path + "/media/materials/programs", "FileSystem", ROS_PACKAGE_NAME ); 00073 } 00074 catch ( Ogre::Exception& e ) 00075 { 00076 printf( "Failed to initialize Ogre: %s\n", e.what() ); 00077 throw; 00078 } 00079 } 00080 00081 void cleanupOgre() 00082 { 00083 delete Ogre::Root::getSingletonPtr(); 00084 } 00085 00086 void initializeResources( const V_string& resource_paths ) 00087 { 00088 V_string::const_iterator path_it = resource_paths.begin(); 00089 V_string::const_iterator path_end = resource_paths.end(); 00090 for( ; path_it != path_end; ++path_it ) 00091 { 00092 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( *path_it, "FileSystem", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ); 00093 } 00094 00095 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 00096 } 00097 00098 } // namespace ogre_tools