コード例 #1
0
ファイル: App.cpp プロジェクト: lilyrae/ShowARoom
void App::initOgre()
{
#ifdef _DEBUG
    mRoot = new Ogre::Root("plugins_d.cfg");
#else
    mRoot = new Ogre::Root("plugins.cfg");
#endif
    mRoot->addFrameListener(this);

    // Load up resources according to resources.cfg:
    Ogre::ConfigFile cf;
    cf.load("resources.cfg");

    // Go through all sections & settings in the file
    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();

    Ogre::String secName, typeName, archName;
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey();
        Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i)
        {
            typeName = i->first;
            archName = i->second;
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
                archName, typeName, secName);
        }
    }

    Ogre::RenderSystem* pRS = mRoot->getRenderSystemByName("OpenGL Rendering Subsystem");
    Ogre::ConfigOptionMap cfgMap = pRS->getConfigOptions();
    cfgMap["Full Screen"].currentValue = "No";
    cfgMap["VSync"].currentValue = "Yes";
#ifdef _DEBUG
    cfgMap["FSAA"].currentValue = "0";
#else
    cfgMap["FSAA"].currentValue = "8";
#endif
    cfgMap["Video Mode"].currentValue = "1200 x 800";
    for(Ogre::ConfigOptionMap::iterator iter = cfgMap.begin(); iter != cfgMap.end(); iter++) pRS->setConfigOption(iter->first, iter->second.currentValue);
    mRoot->setRenderSystem(pRS);
    mRoot->initialise(false, "Oculus Rift Visualization");

    // Create the Windows:
    Ogre::NameValuePairList miscParams;
    if( NO_RIFT )
        miscParams["monitorIndex"] = Ogre::StringConverter::toString(0);
    else
        miscParams["monitorIndex"] = Ogre::StringConverter::toString(1);
    miscParams["border "] = "none";

    Ogre::NameValuePairList miscParamsSmall;
    miscParamsSmall["monitorIndex"] = Ogre::StringConverter::toString(0);

    if( !ROTATE_VIEW )
        mWindow = mRoot->createRenderWindow("ShowARoom", WIDTH, HEIGHT, FULL_SCREEN, &miscParams);
    //mWindow = mRoot->createRenderWindow("Oculus Rift Liver Visualization", 1920*0.5, 1080*0.5, false, &miscParams);
    else
        mWindow = mRoot->createRenderWindow("ShowARoom", HEIGHT, WIDTH, FULL_SCREEN, &miscParams);

    if( DEBUG_WINDOW )
        mSmallWindow = mRoot->createRenderWindow("DEBUG ShowARoom", 1920*debugWindowSize, 1080*debugWindowSize, false, &miscParamsSmall);

    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}
コード例 #2
0
ファイル: App.cpp プロジェクト: fakkoweb/OgreOculusApp
void App::initOgre()
{
	// Config file class is an utility that parses and stores values from a .cfg file
	Ogre::ConfigFile cf;
	std::string configFilePathPrefix = "cfg/";			// configuration files default location when app is installed
#ifdef _DEBUG
	std::string pluginsFileName = "plugins_d.cfg";		// plugins config file name (Debug mode)
#else
	std::string pluginsFileName = "plugins.cfg";		// plugins config file name (Release mode)
#endif
	std::string resourcesFileName = "resources.cfg";	// resources config file name (Debug/Release mode)


	// LOAD OGRE PLUGINS
	// Try to load load up a valid config file (and don't start the program if none is found)
	try
	{
		//This will work ONLY when application is installed (only Release application)!
		cf.load(configFilePathPrefix + pluginsFileName);
	}
	catch (Ogre::FileNotFoundException &e)
	{
		try
		{
			// if no existing config, or could not restore it, try to load from a different location
			configFilePathPrefix = "../cfg/";

			//This will work ONLY when application is in development (Debug/Release configuration)
			cf.load(configFilePathPrefix + pluginsFileName);			
		}
		catch (Ogre::FileNotFoundException &e)
		{
			// launch exception if no valid config file is found! - PROGRAM WON'T START!
			throw e;
		}
	}


	// INSTANCIATE OGRE ROOT (IT INSTANCIATES ALSO ALL OTHER OGRE COMPONENTS)
	// In Ogre, the singletons are instanciated explicitly (with new) the first time,
	// then it can be accessed with Ogre::Root::getSingleton()
	// Plugins are passed as argument to the "Root" constructor
	mRoot = new Ogre::Root(configFilePathPrefix + pluginsFileName, configFilePathPrefix + "ogre.cfg", "ogre.log");
	// No Ogre::FileNotFoundException is thrown by this, that's why we tried to open it first with ConfigFile::load()

	
	// LOAD OGRE RESOURCES
	// Load up resources according to resources.cfg ("cf" variable is reused)
	try
	{
		//This will work ONLY when application is installed!
		cf.load("cfg/resources.cfg");
	}
	catch (Ogre::FileNotFoundException &e)	// It works, no need to change anything
	{
		try
		{
			//This will work ONLY when application is in development (Debug/Release configuration)
			cf.load("../cfg/resources.cfg");
		}
		catch (Ogre::FileNotFoundException &e)
		{
			// launch exception if no valid config file is found! - PROGRAM WON'T START!
			throw e;
		}
	}

    // Go through all sections & settings in the file
    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
    Ogre::String secName, typeName, archName;
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey(); Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i)
        {
            typeName = i->first;
            archName = i->second;
			//For each section/key-value, add a resource to ResourceGroupManager
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
                archName, typeName, secName);
        }
	}


	// Then setup THIS CLASS INSTANCE as a frame listener
	// This means that Ogre will call frameStarted(), frameRenderingQueued() and frameEnded()
	// automatically and periodically if defined in this class
	mRoot->addFrameListener(this);


	// SELECT AND CUSTOMIZE OGRE RENDERING (OpenGL)
	// Get a reference of the RenderSystem in Ogre that I want to customize
	Ogre::RenderSystem* pRS = mRoot->getRenderSystemByName("OpenGL Rendering Subsystem");
	// Get current config RenderSystem options in a ConfigOptionMap
	Ogre::ConfigOptionMap cfgMap = pRS->getConfigOptions();
	// Modify them
	cfgMap["Full Screen"].currentValue = "No";
	cfgMap["VSync"].currentValue = "Yes";
	#ifdef _DEBUG
		cfgMap["FSAA"].currentValue = "0";
	#else
		cfgMap["FSAA"].currentValue = "8";
	#endif
	cfgMap["Video Mode"].currentValue = "1200 x 800";
	// Set them back into the RenderSystem
	for(Ogre::ConfigOptionMap::iterator iter = cfgMap.begin(); iter != cfgMap.end(); iter++) pRS->setConfigOption(iter->first, iter->second.currentValue);
	// Set this RenderSystem as the one I want to use
	mRoot->setRenderSystem(pRS);
	// Initialize it: "false" is DO NOT CREATE A WINDOW FOR ME
	mRoot->initialise(false, "Oculus Rift Visualization");


	// CREATE WINDOWS
	/* REMOVED: Rift class creates the window if no null is passed to its constructor
	// Options for Window 1 (rendering window)
	Ogre::NameValuePairList miscParams;
	if( NO_RIFT )
		miscParams["monitorIndex"] = Ogre::StringConverter::toString(0);
	else
		miscParams["monitorIndex"] = Ogre::StringConverter::toString(1);
	miscParams["border "] = "none";
	*/

	/*
	// Create Window 1
	if( !ROTATE_VIEW )
	mWindow = mRoot->createRenderWindow("Oculus Rift Liver Visualization", 1280, 800, true, &miscParams);
	//mWindow = mRoot->createRenderWindow("Oculus Rift Liver Visualization", 1920*0.5, 1080*0.5, false, &miscParams);
	else
	mWindow = mRoot->createRenderWindow("Oculus Rift Liver Visualization", 1080, 1920, true, &miscParams);
	*/

	// Options for Window 2 (debug window)
	// This window will simply show what the two cameras see in two different viewports
	Ogre::NameValuePairList miscParamsSmall;
	miscParamsSmall["monitorIndex"] = Ogre::StringConverter::toString(0);

	// Create Window 2
	if( DEBUG_WINDOW )
		mSmallWindow = mRoot->createRenderWindow("DEBUG Oculus Rift Liver Visualization", 1920*debugWindowSize, 1080*debugWindowSize, false, &miscParamsSmall);   

	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}
コード例 #3
0
ファイル: vpAROgre.cpp プロジェクト: tswang/visp
/*!
  Initialisation of Ogre.

  Load the plugins that are specified in the plugins.cfg or
  plugins_d.cfg files. These files are located in
  VISP_HAVE_OGRE_PLUGINS_PATH folder that is defined in vpConfig.h.
  Note that plugins.cfg file is always considered under Unix
  platforms. The file plugins_d.cfg is only considered under Windows
  when the build type is Debug.

  Load also the resources that are defined in the resources.cfg
  file. This file is located in VISP_HAVE_OGRE_RESOURCES_PATH folder
  that is defined in vpConfig.h.

  \param bufferedKeys : If true, use of buffered input for the keyboard (see
  Ogre documentation). Note that this parameter is only useful if OIS is used.

  \param hidden : If true, the created window will be hidden.
  Note that this functionnality requires Ogre3D 1.8.1 at least.

  \exception vpException::ioError : If the required plugins.cfg /
  plugins_d.cfg or resources.cfg files are not accessible.

*/
void vpAROgre::init(bool
#ifdef VISP_HAVE_OIS
		    bufferedKeys
#endif
        ,bool hidden
		    )
{
  // Create the root
  // mPluginsPath may contain more than one folder location separated by ";"
  bool pluginsFileExists = false;
  std::string pluginFile;
  std::vector<std::string> plugingsPaths = vpIoTools::splitChain(std::string(mPluginsPath), std::string(";"));
  for (size_t i=0; i<plugingsPaths.size(); i++) {
#if defined(NDEBUG) || !defined(_WIN32)
    pluginFile = plugingsPaths[i]+"/plugins.cfg";
#else
    pluginFile = plugingsPaths[i]+"/plugins_d.cfg";
#endif

    if(vpIoTools::checkFilename(pluginFile)) {
      pluginsFileExists = true;
      break;
    }
  }
  if (! pluginsFileExists) {
    std::string errorMsg = std::string("Error: the requested plugins file \"")
#if defined(NDEBUG) || !defined(_WIN32)
        + std::string("plugins.cfg")
#else
        + std::string("plugins_d.cfg")
#endif
    + std::string("\" doesn't exist in ")
    + std::string(mPluginsPath);
    std::cout << errorMsg << std::endl;

    throw (vpException(vpException::ioError, errorMsg));
  }
  std::cout << "######################### Load plugin file: " << pluginFile << std::endl;

  if(Ogre::Root::getSingletonPtr() == NULL)
    mRoot = new Ogre::Root(pluginFile, "ogre.cfg", "Ogre.log");
  else
    mRoot = Ogre::Root::getSingletonPtr();

  // Load resource paths from config file

  // File format is:
  //  [ResourceGroupName]
  //  ArchiveType=Path
  //  .. repeat
  // For example:
  //  [General]
  //  FileSystem=media/
  //  Zip=packages/level1.zip

  // mResourcePath may contain more than one folder location separated by ";"
  bool resourcesFileExists = false;
  std::string resourceFile;
  std::vector<std::string> resourcesPaths = vpIoTools::splitChain(std::string(mResourcePath), std::string(";"));
  for (size_t i=0; i<resourcesPaths.size(); i++) {
    resourceFile = resourcesPaths[i]+"/resources.cfg";
    if(vpIoTools::checkFilename(resourceFile)) {
      resourcesFileExists = true;
      break;
    }
  }
  if (! resourcesFileExists) {
    std::string errorMsg = std::string("Error: the requested resource file \"resources.cfg\"")
        + std::string("doesn't exist in ")
        + std::string(mResourcePath);

    std::cout << errorMsg << std::endl;

    throw (vpException(vpException::ioError, errorMsg));
  }
  std::cout << "######################### Load resource file: " << resourceFile << std::endl;
  Ogre::ConfigFile cf;
  cf.load(resourceFile);

  // Go through all sections & settings in the file
  Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();

  Ogre::String secName, typeName, archName;
  while (seci.hasMoreElements())
    {
      secName = seci.peekNextKey();
      Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
      Ogre::ConfigFile::SettingsMultiMap::iterator i;
      for (i = settings->begin(); i != settings->end(); ++i)
	{
	  typeName = i->first;
	  archName = i->second;
	  Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
									 archName, typeName, secName);
	}
    }
    std::cout << "##################### add resources" << std::endl;
  //Add optionnal resources (given by the user).
  for(std::list<std::string>::const_iterator iter = mOptionnalResourceLocation.begin(); iter != mOptionnalResourceLocation.end(); ++iter){
    Ogre::ResourceGroupManager::getSingleton().addResourceLocation(*iter, "FileSystem", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
  }

  // Create the window
  bool canInit = true;
  if(mshowConfigDialog){
    mRoot->restoreConfig();
    if(!mRoot->showConfigDialog())
      canInit = false;
  }
  else{
    if(!mRoot->restoreConfig())
      canInit = false;
  }

  if(!mRoot->isInitialised()){
    if(!canInit){ //We set the default renderer system
      const Ogre::RenderSystemList& lRenderSystemList = mRoot->getAvailableRenderers();
      if( lRenderSystemList.size() == 0 )
        throw "ConfigDialog aborted"; // Exit the application on cancel

      Ogre::RenderSystem *lRenderSystem = lRenderSystemList.at(0);
      std::cout << "Using " << lRenderSystem->getName() << " as renderer." << std::endl;
      mRoot->setRenderSystem(lRenderSystem);
    }

    mRoot->initialise(false);
  }

  bool fullscreen = false;
  Ogre::NameValuePairList misc;
  Ogre::ConfigOptionMap config = mRoot->getRenderSystem()->getConfigOptions();
  Ogre::ConfigOptionMap::const_iterator it = config.begin();

  while( it != config.end() ){
    Ogre::String leftconf = (*it).first;
    Ogre::String rightconf = (*it).second.currentValue;

    if(leftconf == "Video Mode"){
      if(canInit) {
        int ret = sscanf(rightconf.c_str(), "%d %*s %d", &mWindowWidth, &mWindowHeight);
        if (ret == 0)
          std::cout << "Cannot read Ogre video mode" << std::endl;
      }
      else{
        if(mWindowWidth == 0 && mWindowHeight == 0){
          mWindowWidth = mBackgroundWidth;
          mWindowHeight = mBackgroundHeight;
        }
      }
    }
    else if( leftconf == "Full Screen" ){
      if(canInit){
        if(rightconf == "Yes") fullscreen = true;
      }
    }
    else
      misc[leftconf] = rightconf;

    it++;
  }

  // With Ogre version >= 1.8.1 we hide the window
  if( hidden ){
#if ( OGRE_VERSION >= (1 << 16 | 8 << 8 | 1) )
    misc["hidden"] = "true";
    windowHidden = true;
#endif
  }
  mWindow = mRoot->createRenderWindow(name, mWindowWidth, mWindowHeight, fullscreen, &misc);

  // Initialise resources
  Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
  //-----------------------------------------------------
  // 4 Create the SceneManager
  //
  //		ST_GENERIC = octree
  //		ST_EXTERIOR_CLOSE = simple terrain
  //		ST_EXTERIOR_FAR = nature terrain (depreciated)
  //		ST_EXTERIOR_REAL_FAR = paging landscape
  //		ST_INTERIOR = Quake3 BSP
  //-----------------------------------------------------

  mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC);

  // Create the camera
  createCamera();

  // Create a viewport
  Ogre::Viewport* viewPort = mWindow->addViewport(mCamera);
//   Ogre::Viewport* viewPort = mCamera->getViewport();
  viewPort->setClearEveryFrame(true);
  // Set the projection parameters to match the camera intrinsic parameters
  updateCameraProjection();

  // Create the 3D scene
  createScene();

  // Initialise and register event handlers
  mRoot->addFrameListener(this);

  // Register as a Window listener
  Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this);

#ifdef VISP_HAVE_OIS
  // Initialise OIS
  Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
  OIS::ParamList pl;

  size_t windowHnd = 0;
  std::ostringstream windowHndStr;
  // Initialise window
  mWindow->getCustomAttribute("WINDOW", &windowHnd);
  windowHndStr << windowHnd;
  pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
  // Let the user use the keyboard elsewhere
#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
  pl.insert(std::make_pair(std::string("x11_keyboard_grab"), std::string("false")));
#endif

  mInputManager = OIS::InputManager::createInputSystem( pl );

  //Create all devices
  // Here we only consider the keyboard input
  mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject( OIS::OISKeyboard, bufferedKeys ));
  if ( !bufferedKeys ) mKeyboard->setEventCallback ( this);
#endif

  // Initialise a render to texture to be able to retrieve a screenshot
  Ogre::TexturePtr Texture = Ogre::TextureManager::getSingleton().createManual("rtf", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,Ogre::TEX_TYPE_2D,
                                                                               mWindow->getWidth(),mWindow->getHeight(), 0, Ogre::PF_R8G8B8A8, Ogre::TU_RENDERTARGET);



//   Ogre::TexturePtr Texture = Ogre::TextureManager::getSingleton().createManual("rtf", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,Ogre::TEX_TYPE_2D,
//                                                                                640,480, 0, Ogre::PF_R8G8B8A8, Ogre::TU_RENDERTARGET);
  Ogre::RenderTexture* RTarget = Texture->getBuffer()->getRenderTarget();
  /*Ogre::Viewport* Viewport =*/ RTarget->addViewport(mCamera);
  RTarget->getViewport(0)->setClearEveryFrame(true);
  RTarget->getViewport(0)->setOverlaysEnabled(false);
}