Esempio n. 1
0
	bool CServer::configureOgre(bool force)
	{
		//////////////////
		// OGRE         //
		//////////////////

		// Carga los ajustes de configudación desde ogre.cfg
		if(force || !_root->restoreConfig()) {
			//// Si no hay archivo de configuración se lanza la ventana de configuración
			//if(!_root->showConfigDialog()) {
			//	// Si el juego no se puede configurar se finaliza
			//	return false;
			//}

			///seteamos la resolucion y el rendersystem a mano
			Ogre::RenderSystemList rs = _root->getAvailableRenderers();
			Ogre::RenderSystemList::iterator it = rs.begin();

			for(; it != rs.end(); ++it)
			{
				if((*it)->getName() == "Direct3D9 Rendering Subsystem")
				{
					_root->setRenderSystem((*it));

					(*it)->setConfigOption("Full Screen","No");  
					(*it)->setConfigOption("Video Mode","1280 x 720 @ 32-bit colour");
				}
			}
		}
		return true;

	} // configure
Esempio n. 2
0
GraphicsOgre::GraphicsOgre(const Options *config):
	ogre_{new Ogre::Root("", "")},
	window_{nullptr}
{
	LOG(INFO) << "Initializing Ogre";
	//use OpenGL
	const std::string pluginsFolder = config->getValue<std::string>("ogrePluginsFolder");
	ogre_->loadPlugin(pluginsFolder + "RenderSystem_GL");
	const Ogre::RenderSystemList renderList = ogre_->getAvailableRenderers();
	Ogre::RenderSystemList::const_iterator r_it;
	r_it = renderList.begin();
	ogre_->setRenderSystem(*r_it);
	ogre_->initialise(false);

	//create manualy the window
	Ogre::NameValuePairList opts;
	opts.insert(Ogre::NameValuePairList::value_type("vsync", "false"));
	opts.insert(Ogre::NameValuePairList::value_type("top", "10"));
	opts.insert(Ogre::NameValuePairList::value_type("left", "10"));
	window_ = ogre_->createRenderWindow(
		config->getValue<std::string>("appname"), 
		config->getValue<int>("width"), 
		config->getValue<int>("height"), 
		config->getValue<bool>("fullscreen"), 
		&opts);
	//initialize ressources	
	defineRessources();
	Ogre::ResourceGroupManager::getSingleton().loadResourceGroup("General");
}
Esempio n. 3
0
/**
 * @brief init the object
 * @author kito berg-taylor
 */
void OgreWidget::init()
{
  // create the main ogre object
  mOgreRoot = new Ogre::Root;

  mOgreRoot->loadPlugin("RenderSystem_GL");
  Ogre::String rName("OpenGL Rendering Subsystem");
  Ogre::RenderSystemList rList = mOgreRoot->getAvailableRenderers();
  Ogre::RenderSystemList::iterator it = rList.begin();
  Ogre::RenderSystem *rSys = 0;
  while(it != rList.end())
  {
    rSys = * (it++);
    Ogre::String strx=rSys->getName();
    if(strx == rName)
    {
      mOgreRoot->setRenderSystem(rSys);
      break;
    }
  }
   QString dimensions = QString( "%1x%2" )
                    .arg(this->width())
                    .arg(this->height());
 
  rSys->setConfigOption( "Video Mode", dimensions.toStdString() );
 
  // initialize without creating window
  mOgreRoot->getRenderSystem()->setConfigOption( "Full Screen", "No" );
  mOgreRoot->saveConfig();
  mOgreRoot->initialise(false); // don't create a window
}
Esempio n. 4
0
void OgreMinimalSetup::debugRenderList(const Ogre::RenderSystemList& rsl)
{
  assert(rsl.size() && "RenderSystemList size is 0");
  cout << "RenderSystemList size is " << rsl.size() << endl;
  Ogre::RenderSystem* rs = rsl[0];
  assert(rs && "First RenderSystem is NULL");
  cout << "First RenderSystem name is '" << rs->getName() << "'" << endl;
}
Esempio n. 5
0
void OgreWidget::init( std::string plugins_file,  std::string ogre_cfg_file, std::string ogre_log )
{
  mOgreRoot = new Ogre::Root( plugins_file, ogre_cfg_file, ogre_log );
  Ogre::RenderSystemList renderers = mOgreRoot->getAvailableRenderers();
  assert( !renderers.empty() );
  Ogre::RenderSystem *renderSystem = chooseRenderer(& renderers );
  assert( renderSystem );
  mOgreRoot->setRenderSystem( renderSystem );
  QString dimensions = QString( "%1x%2" ).arg(this->width()).arg(this->height());
  renderSystem->setConfigOption( "Video Mode", dimensions.toStdString() );
  mOgreRoot->getRenderSystem()->setConfigOption( "Full Screen", "No" );
  mOgreRoot->saveConfig();
  mOgreRoot->initialise(false);
  initResourses();
}
//------------------------------------------------------------------------------
void wxOgreRenderSystem::SelectOgreRenderSystem(const Ogre::String& render)
{
    Ogre::RenderSystemList renderList;
    Ogre::RenderSystemList::iterator it;

    renderList = m_root->getAvailableRenderers();
    // check through all available renderers, if there is one the
    // string is "render"
    for (it = renderList.begin(); it != renderList.end(); ++it) {
        Ogre::RenderSystem* renderSys = *it;
        if (std::string (renderSys->getName()) == render) {
            m_root->setRenderSystem(renderSys);
            break;
        }
    }

}
void
dmz::RenderModuleCoreOgreBasic::_init_render_system (Config &local) {

   if (_root) {

      String renderSystemName (
         config_to_string ("renderSystem.name", local, "OpenGL"));

      Ogre::RenderSystem *renderSystem (0);

      Ogre::RenderSystemList *renderSystemList = _root->getAvailableRenderers ();
      if (renderSystemList) {

         Ogre::RenderSystemList::iterator it = renderSystemList->begin ();
         while (it != renderSystemList->end () && !renderSystem) {

            if (renderSystemList->size () == 1) {

               renderSystem = *it;
            }
            else {

               Ogre::String curName ((*it)->getName ());
               if (curName.find (renderSystemName.get_buffer ()) >= 0) {

                  renderSystem = *it;
               }
            }

            it++;
         }
      }

      if (renderSystem) {

         _root->setRenderSystem (renderSystem);
         _root->initialise (false); // don't autocreate a window
      }
      else {

         _log.error
            << "Specified render system (" << renderSystemName << ") not found" << endl;
      }
   }
}
Esempio n. 8
0
  virtual void SetUp()
  {
    Ogre::LogManager* log_manager = new Ogre::LogManager();
    log_manager->createLog( "Ogre.log", false, false, true );

    g_root = new Ogre::Root();
    g_root->loadPlugin( "RenderSystem_GL" );
    g_root->loadPlugin( "Plugin_OctreeSceneManager" );

    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    // Taken from gazebo
    Ogre::RenderSystemList *rsList = g_root->getAvailableRenderers();

    Ogre::RenderSystem* render_system = NULL;
    Ogre::RenderSystemList::iterator renderIt = rsList->begin();
    Ogre::RenderSystemList::iterator renderEnd = rsList->end();
    for ( ; renderIt != renderEnd; ++renderIt )
    {
      render_system = *renderIt;

      if ( render_system->getName() == "OpenGL Rendering Subsystem" )
      {
        break;
      }
    }

    if ( render_system == NULL )
    {
      printf( "Could not find the opengl rendering subsystem!\n" );
      exit(1);
    }

    render_system->setConfigOption("Full Screen","No");
    render_system->setConfigOption("FSAA","2");
    render_system->setConfigOption("RTT Preferred Mode", "PBuffer");

    g_root->setRenderSystem( render_system );
    g_render_window = g_root->initialise( true );
    g_scene_manager = g_root->createSceneManager( Ogre::ST_GENERIC, "TestSceneManager" );
    g_viewport = g_render_window->addViewport( NULL );

    g_root->renderOneFrame();
  }
Esempio n. 9
0
void OgreWidget::initialiseOgre(void)
{
    Ogre::RenderSystem* Direct3D9RenderSystem = 0;

    try
    {
        mRoot->loadPlugin("RenderSystem_Direct3D9");
    }
    catch (...)
    {
        qWarning("Failed to load Direct3D9 plugin");
    }

    Ogre::RenderSystemList list = Ogre::Root::getSingletonPtr()->getAvailableRenderers();
    Ogre::RenderSystemList::iterator i = list.begin();

    while (i != list.end())
    {
        if ((*i)->getName() == "Direct3D9 Rendering Subsystem")
        {
            Direct3D9RenderSystem = *i;
        }
        i++;
    }

    if (!Direct3D9RenderSystem)
    {
        qCritical("No rendering subsystems found");
        exit(0);
    }

    if (Direct3D9RenderSystem != 0)
    {
        mActiveRenderSystem = Direct3D9RenderSystem;
    }

    Ogre::Root::getSingletonPtr()->setRenderSystem(mActiveRenderSystem);
    Ogre::Root::getSingletonPtr()->initialise(false);

    mRoot->addFrameListener(this);
}
Esempio n. 10
0
bool GraphicsImpl::configure()
{
	Dout <<"Setting Rendering Subsystem" ;

	Ogre::RenderSystemList renderers = root->getAvailableRenderers();

	if (renderers.empty()) {
		Dout <<"No rendering system available" ;
		return false;
	}

	root->setRenderSystem(renderers.front());

	Dout <<"Init Root" ;

	root->initialise(false);

	Dout <<"Create window" ;

	window = root->createRenderWindow("Manual Ogre Window", boost::any_cast<int>(SettingsManager::Instance().getSetting("x_res").data), boost::any_cast<int>(SettingsManager::Instance().getSetting("y_res").data), false, 0);                      // use defaults for all other values


	return true;
}
Esempio n. 11
0
void CLASS::UpdateControls()
{

	int valuecounter = 0; // Going to be usefull for selections

	//Lang (Still not done)
	if (!IsLoaded)
	{
		m_lang->addItem("English (U.S.)");
	}
	m_lang->setIndexSelected(0); //TODO

	if (!IsLoaded)
	{
		m_gearbox_mode->addItem("Automatic shift");
		m_gearbox_mode->addItem("Manual shift - Auto clutch");
		m_gearbox_mode->addItem("Fully Manual: sequential shift");
		m_gearbox_mode->addItem("Fully Manual: stick shift");
		m_gearbox_mode->addItem("Fully Manual: stick shift with ranges");
	}

	//Gearbox
	Ogre::String gearbox_mode = GameSettingsMap["GearboxMode"];
	if (gearbox_mode == "Manual shift - Auto clutch")
		m_gearbox_mode->setIndexSelected(1);
	else if (gearbox_mode == "Fully Manual: sequential shift")
		m_gearbox_mode->setIndexSelected(2);
	else if (gearbox_mode == "Fully Manual: stick shift")
		m_gearbox_mode->setIndexSelected(3);
	else if (gearbox_mode == "Fully Manual: stick shift with ranges")
		m_gearbox_mode->setIndexSelected(4);
	else
		m_gearbox_mode->setIndexSelected(0);


	Ogre::RenderSystem* rs = Ogre::Root::getSingleton().getRenderSystem();
	// add all rendersystems to the list
	if (m_render_sys->getItemCount() == 0)
	{
		const Ogre::RenderSystemList list = Application::GetOgreSubsystem()->GetOgreRoot()->getAvailableRenderers();
		int selection = 0;
		for (Ogre::RenderSystemList::const_iterator it = list.begin(); it != list.end(); it++, valuecounter++)
		{
			if (rs && rs->getName() == (*it)->getName())
			{
				ExOgreSettingsMap["Render System"] = rs->getName();
				selection = valuecounter;
			}
			else if (!rs) {
				LOG("Error: No Ogre Render System found");
			}
			if (!IsLoaded)
			{
				m_render_sys->addItem(Ogre::String((*it)->getName()));
			}
		}
		m_render_sys->setIndexSelected(selection);
	}

	Ogre::ConfigFile cfg;
	cfg.load(SSETTING("ogre.cfg", "ogre.cfg"));

	//Few GameSettingsMap
	Ogre::String bFullScreen = cfg.getSetting("Full Screen", rs->getName());
	if (bFullScreen == "Yes")
	{
		ExOgreSettingsMap["Full Screen"] = "Yes";
		m_fullscreen->setStateCheck(true);
	}
	else
	{
		ExOgreSettingsMap["Full Screen"] = "No";
		m_fullscreen->setStateCheck(false);
	}

	Ogre::String bVsync = cfg.getSetting("VSync", rs->getName());
	if (bVsync == "Yes")
	{
		ExOgreSettingsMap["VSync"] = "Yes";
		m_vsync->setStateCheck(true);
	}
	else
	{
		ExOgreSettingsMap["VSync"] = "No";
		m_vsync->setStateCheck(false);
	}
		
	// store available rendering devices and available resolutions
	Ogre::ConfigOptionMap& CurrentRendererOptions = rs->getConfigOptions();
	Ogre::ConfigOptionMap::iterator configItr = CurrentRendererOptions.begin();
	Ogre::StringVector mFoundResolutions;
	Ogre::StringVector mFoundFSAA;
	while (configItr != CurrentRendererOptions.end())
	{
		if ((configItr)->first == "Video Mode")
		{
			// Store Available Resolutions
			mFoundResolutions = ((configItr)->second.possibleValues);
		}
		if ((configItr)->first == "FSAA")
		{
			// Store Available Resolutions
			mFoundFSAA = ((configItr)->second.possibleValues);
		}
		configItr++;
	}

	//Loop thru the vector for the resolutions
	valuecounter = 0; //Back to default
	Ogre::StringVector::iterator iterRes = mFoundResolutions.begin();
	for (; iterRes != mFoundResolutions.end(); iterRes++)
	{
		if (!IsLoaded)
		{
			m_resolution->addItem(Ogre::String((iterRes)->c_str()));
		}
		if ((iterRes)->c_str() == cfg.getSetting("Video Mode", rs->getName()))
		{
			ExOgreSettingsMap["Video Mode"] = (iterRes)->c_str();
			m_resolution->setIndexSelected(valuecounter);
		}
		valuecounter++;
	}

	//Loop thru the vector for the FSAAs
	valuecounter = 0; //Back to default
	Ogre::StringVector::iterator iterFSAA = mFoundFSAA.begin();
	for (; iterFSAA != mFoundFSAA.end(); iterFSAA++)
	{
		if (!IsLoaded)
		{
			m_fsaa->addItem(Ogre::String((iterFSAA)->c_str()));
		}
		if ((iterFSAA)->c_str() == cfg.getSetting("FSAA", rs->getName()))
		{
			ExOgreSettingsMap["FSAA"] = (iterFSAA)->c_str();
			m_fsaa->setIndexSelected(valuecounter);
		}
		
		valuecounter++;
	}

	//Few GameSettingsMap
	if (GameSettingsMap["ArcadeControls"] == "Yes")
		m_arc_mode->setStateCheck(true);
	else
		m_arc_mode->setStateCheck(false);

	if (GameSettingsMap["External Camera Mode"] == "Static")
		m_d_cam_pitch->setStateCheck(true);
	else
		m_d_cam_pitch->setStateCheck(false);

	if (GameSettingsMap["Creak Sound"] == "No")
		m_d_creak_sound->setStateCheck(true);
	else
		m_d_creak_sound->setStateCheck(false);

	//Fov
	m_fovexternal->setCaption(GameSettingsMap["FOV External"]);
	m_fovinternal->setCaption(GameSettingsMap["FOV Internal"]);

	
	//Texture Filtering
	Ogre::String texfilter = GameSettingsMap["Texture Filtering"];
	if (texfilter == "Bilinear")
		m_tex_filter->setIndexSelected(1);
	else if (texfilter == "Trilinear")
		m_tex_filter->setIndexSelected(2);
	else if (texfilter == "Anisotropic (best looking)")
		m_tex_filter->setIndexSelected(3);
	else
		m_tex_filter->setIndexSelected(0);

	if (!IsLoaded)
	{
		m_water_type->addItem("Hydrax"); //It's working good enough to be here now. 
	}

	if (BSETTING("DevMode", false) && !IsLoaded)
	{
		//Things that aren't ready to be used yet.
		m_sky_type->addItem("SkyX (best looking, slower)");
		m_shadow_type->addItem("Parallel-split Shadow Maps");
	}

	//Sky effects
	Ogre::String skytype = GameSettingsMap["Sky effects"];
	if (skytype == "Caelum (best looking, slower)")
		m_sky_type->setIndexSelected(1);
	else if (skytype == "SkyX (best looking, slower)" && BSETTING("DevMode", false))
		m_sky_type->setIndexSelected(2);
	else
		m_sky_type->setIndexSelected(0);

	//Shadow technique
	Ogre::String shadowtype = GameSettingsMap["Shadow technique"];
	if (shadowtype == "Texture shadows")
		m_shadow_type->setIndexSelected(1);
	else if (shadowtype == "Stencil shadows (best looking)")
		m_shadow_type->setIndexSelected(2);
	else if (shadowtype == "Parallel-split Shadow Maps" && BSETTING("DevMode", false))
		m_shadow_type->setIndexSelected(3);
	else
		m_shadow_type->setIndexSelected(0);

	//Water effects
	Ogre::String watertype = GameSettingsMap["Water effects"];
	if (watertype == "Reflection")
		m_water_type->setIndexSelected(1);
	else if (watertype == "Reflection + refraction (speed optimized)")
		m_water_type->setIndexSelected(2);
	else if (watertype == "Reflection + refraction (quality optimized)")
		m_water_type->setIndexSelected(3);
	else if (watertype == "Hydrax")
		m_water_type->setIndexSelected(4);
	else
		m_water_type->setIndexSelected(0);
		
	//Vegetation
	Ogre::String vegetationtype = GameSettingsMap["Vegetation"];
	if (vegetationtype == "20%")
		m_vegetation->setIndexSelected(1);
	else if (vegetationtype == "50%")
		m_vegetation->setIndexSelected(2);
	else if (vegetationtype == "Full (best looking, slower)")
		m_vegetation->setIndexSelected(3);
	else
		m_vegetation->setIndexSelected(0);

	//Light source effects
	Ogre::String lightstype = GameSettingsMap["Lights"];
	if (lightstype == "Only current vehicle, main lights")
		m_light_source_effects->setIndexSelected(1);
	else if (lightstype == "All vehicles, main lights")
		m_light_source_effects->setIndexSelected(2);
	else if (lightstype == "All vehicles, all lights")
		m_light_source_effects->setIndexSelected(3);
	else
		m_light_source_effects->setIndexSelected(0);
	
	//Speed until selection
	Ogre::String speedunit = GameSettingsMap["SpeedUnit"];
	if (speedunit == "Metric")
		m_speed_unit->setIndexSelected(1);
	else
		m_speed_unit->setIndexSelected(0);

	//Other configs
	if (GameSettingsMap["DigitalSpeedo"] == "Yes")
		m_digital_speedo->setStateCheck(true);
	else
		m_digital_speedo->setStateCheck(false);

	if (GameSettingsMap["Particles"] == "Yes")
		m_psystem->setStateCheck(true);
	else
		m_psystem->setStateCheck(false);

	if (GameSettingsMap["HeatHaze"] == "Yes")
		m_heathaze->setStateCheck(true);
	else
		m_heathaze->setStateCheck(false);

	if (GameSettingsMap["Mirrors"] == "Yes")
		m_mirrors->setStateCheck(true);
	else
		m_mirrors->setStateCheck(false);

	if (GameSettingsMap["Sunburn"] == "Yes")
		m_sunburn->setStateCheck(true);
	else
		m_sunburn->setStateCheck(false);

	if (GameSettingsMap["HDR"] == "Yes")
		m_hdr->setStateCheck(true);
	else
		m_hdr->setStateCheck(false);

	if (GameSettingsMap["Motion blur"] == "Yes")
		m_mblur->setStateCheck(true);
	else
		m_mblur->setStateCheck(false);

	if (GameSettingsMap["Skidmarks"] == "Yes")
		m_skidmarks->setStateCheck(true);
	else
		m_skidmarks->setStateCheck(false);

	if (GameSettingsMap["Envmap"] == "Yes")
		m_hq_ref->setStateCheck(true);
	else
		m_hq_ref->setStateCheck(false);

	if (GameSettingsMap["Glow"] == "Yes")
		m_glow->setStateCheck(true);
	else
		m_glow->setStateCheck(false);

	if (GameSettingsMap["DOF"] == "Yes")
		m_dof->setStateCheck(true);
	else
		m_dof->setStateCheck(false);

	if (GameSettingsMap["Waves"] == "Yes")
		m_e_waves->setStateCheck(true);
	else
		m_e_waves->setStateCheck(false);

	if (GameSettingsMap["Shadow optimizations"] == "Yes")
		m_sh_pf_opti->setStateCheck(true);
	else
		m_sh_pf_opti->setStateCheck(false);

	if (GameSettingsMap["AsynchronousPhysics"] == "Yes")
		m_enable_async_physics->setStateCheck(true);
	else
		m_enable_async_physics->setStateCheck(false);

	if (GameSettingsMap["DisableCollisions"] == "Yes")
		m_disable_inter_collsion->setStateCheck(true);
	else
		m_disable_inter_collsion->setStateCheck(false);

	if (GameSettingsMap["DisableSelfCollisions"] == "Yes")
		m_disable_intra_collision->setStateCheck(true);
	else
		m_disable_intra_collision->setStateCheck(false);

	if (GameSettingsMap["Multi-threading"] == "No")
		m_disable_multithreading->setStateCheck(true);
	else
		m_disable_multithreading->setStateCheck(false);

	//Volume slider
	long sound_volume = Ogre::StringConverter::parseLong(GameSettingsMap["Sound Volume"], 100);
	m_volume_slider->setScrollRange(101);
	m_volume_slider->setScrollPosition(sound_volume -1);
	if (m_volume_slider->getScrollPosition() >= 100)
		m_volume_indicator->setCaption("100%");
	else
		m_volume_indicator->setCaption(Ogre::StringConverter::toString(sound_volume) + "%");

	//Audio Devices
	valuecounter = 0; //Back to default
	char *devices = (char *)alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
	while (devices && *devices != 0)
	{
		if (!IsLoaded)
		{
			m_audio_dev->addItem(Ogre::String(devices));
		}
		if (Ogre::String(devices) == GameSettingsMap["AudioDevice"])
			m_audio_dev->setIndexSelected(valuecounter);

		devices += strlen(devices) + 1; //next device
		valuecounter++;
	}

	//FPS Limiter slider
	long fps_limit = Ogre::StringConverter::parseLong(GameSettingsMap["FPS-Limiter"], 60);
	m_fps_limiter_slider->setScrollRange(200);
	m_fps_limiter_slider->setScrollPosition(fps_limit -1);


	if (fps_limit >= 199)
		m_fps_limiter_indicator->setCaption("Unlimited");
	else
		m_fps_limiter_indicator->setCaption(Ogre::StringConverter::toString(fps_limit) + " FPS");

	//SightRange slider
	long sight_range = Ogre::StringConverter::parseLong(GameSettingsMap["SightRange"], 5000);
	m_sightrange->setScrollRange(5000);
	m_sightrange->setScrollPosition(sight_range -1);
	if (sight_range >= 4999)
		m_sightrange_indicator->setCaption("Unlimited");
	else
		m_sightrange_indicator->setCaption(Ogre::StringConverter::toString(sight_range) + " m");		

	if (GameSettingsMap["Replay mode"] == "Yes")
		m_enable_replay->setStateCheck(true);
	else
		m_enable_replay->setStateCheck(false);

	if (GameSettingsMap["Screenshot Format"] == "png (bigger, no quality loss)")
		m_hq_screenshots->setStateCheck(true);
	else
		m_hq_screenshots->setStateCheck(false);

	if (GameSettingsMap["ChatAutoHide"] == "Yes")
		m_autohide_chatbox->setStateCheck(true);
	else
		m_autohide_chatbox->setStateCheck(false);
}
Esempio n. 12
0
/*!
 * Initialize the application, in particular initialize OGRE and OIS
 * (the input system, see \ref InputHandler).
 *
 * \return TRUE on success, otherwise FALSE. The application should be
 * quit, if initializing failed.
 */
bool TestApp::initialize() {
    if (mOgreRoot) {
        // already initialized
        return true;
    }
    Ogre::String pluginFileName = "plugins.cfg"; // don't use any plugin config file
                                      // (we specify everything by code)
    Ogre::String configFileName = "ogre.cfg"; // don't use any config file
                                      // (we specify everything by code)

    // AB: we create our own logmanager - ogre will use that one.
    Ogre::String logFileName = "Ogre.log"; // AB: name to identify the log - won't necessarily write to a file!
    mOgreLogManager = new Ogre::LogManager();

    // create a default log that ogre itself is going to use.
    bool suppressFileOutput = false;
    bool outputToConsole = true;
    Ogre::Log* log = mOgreLogManager->createLog(logFileName, true, outputToConsole, suppressFileOutput);
    log->addListener(mMyOgreLogListener);

    // AB: atm we don't specify the 3rd parameter and thus use the default Ogre
    //     log filename (Ogre.log in the current dir)
    //     we could just use "" to disable the logfile.
    mOgreRoot = new Ogre::Root(pluginFileName, configFileName);

    // we use OpenGL
    //#if defined __APPLE__ || defined WIN32
    //    mOgreRoot->loadPlugin("RenderSystem_GL");
    //#else
    //    mOgreRoot->loadPlugin(DCOLLIDE_OGRE_PLUGIN_DIR "/RenderSystem_GL");
    //#endif

    Ogre::RenderSystemList* renderSystemList = mOgreRoot->getAvailableRenderers();
    if (renderSystemList->empty()) {
        std::cerr << "Could not load any renderers?!" << std::endl;
        return false;
    }
    Ogre::RenderSystem* renderSystem = renderSystemList->at(0);
    mOgreRoot->setRenderSystem(renderSystem);
    mOgreRoot->initialise(false);


    // Create a window
    int width = 1024;
    int height = 768;
    bool fullscreen = false;
    mRenderWindow = mOgreRoot->createRenderWindow("d-collide test application", width, height, fullscreen);
    if (!mUseGUI) {
        mRenderWindow->setVisible(false);
    }
    mWindowEventListener = new MyWindowEventListener(mRenderWindow);

    mOgreRoot->addResourceLocation("../resources/textures", "FileSystem", "DCollideMaterials");

    mOgreRoot->addResourceLocation("../resources/models", "FileSystem", "DCollideModels");

    // input
    int windowHandle = 0;
    mRenderWindow->getCustomAttribute("WINDOW", &windowHandle);
    mInputHandler = new InputHandler(windowHandle);
    mInputHandler->setTestApp(this);
    mInputHandler->setWindowSize(width, height);
    mWindowEventListener->setInputHandler(mInputHandler);

    // GUI
    mGui = new Gui(mOgreRoot, mRenderWindow);
    mGui->setInputHandler(mInputHandler);
    mGui->addFrameHistory(mFrameHistory, false);
    mGui->addFrameHistory(mGraphicFrameHistory, true);
    mGui->addFrameHistory(mSceneUpdateHistory, true);
    mGui->addFrameHistory(mPhysicsStepHistory, true);
    mGui->addFrameHistory(mCollisionFrameHistory, true);
    if (!mGui->initialize()) {
        std::cerr << "Could not initialize the GUI" << std::endl;
        return false;
    }

    // our actual scene
    changeCurrentScene("default");

    if (!mScene) {
        //error() << "NULL current scene: could not initialize default scene";
        return false;
    }

    mInputHandler->initActions();

    return true;
}
Esempio n. 13
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
#else
int main (int argc, char *argv[]) {
#endif

	Ogre::Root *ogre;
	Ogre::RenderWindow *window;
	Ogre::SceneManager *sceneMgr;
	Ogre::SceneManager *guiSceneMgr;
	Ogre::Camera *camera;
	Ogre::Camera *guiCamera;

	// fire up an Ogre rendering window. Clearing the first two (of three) params will let us 
	// specify plugins and resources in code instead of via text file
	ogre = new Ogre::Root("", "");

#if defined(_DEBUG)
	ogre->loadPlugin("RenderSystem_GL_d");
#else
	ogre->loadPlugin("RenderSystem_GL");
#endif

	Ogre::RenderSystemList *renderSystems = NULL;
	Ogre::RenderSystemList::iterator r_it;

	renderSystems = ogre->getAvailableRenderers();
	r_it = renderSystems->begin();
	ogre->setRenderSystem(*r_it);
	ogre->initialise(false);

	// load common plugins
#if defined(_DEBUG)
	//ogre->loadPlugin("Plugin_CgProgramManager_d");		
	ogre->loadPlugin("Plugin_OctreeSceneManager_d");
#else
	//ogre->loadPlugin("Plugin_CgProgramManager");		
	ogre->loadPlugin("Plugin_OctreeSceneManager");
#endif
	// load the basic resource location(s)
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation("resource", "FileSystem", "General");
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation("resource/gui.zip", "Zip", "GUI");
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation("meshes", "FileSystem", "Meshes");
#if defined(WIN32)
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation("c:\\windows\\fonts", "FileSystem", "GUI");
#endif

	Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
	Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("GUI");
	Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Meshes");

	// setup main window; hardcode some defaults for the sake of presentation
	Ogre::NameValuePairList opts;
	opts["resolution"] = "1024x768";
	opts["fullscreen"] = "false";
	opts["vsync"] = "false";

	// create a rendering window with the title "CDK"
	window = ogre->createRenderWindow("Bouwgame Client v0.1", 1024, 768, false, &opts);

	// since this is basically a CEGUI app, we can use the ST_GENERIC scene manager for now; in a later article 
	// we'll see how to change this
	sceneMgr = ogre->createSceneManager(Ogre::ST_GENERIC);
	guiSceneMgr = ogre->createSceneManager(Ogre::ST_GENERIC);

	guiCamera = guiSceneMgr->createCamera("GUICamera");
	guiCamera->setNearClipDistance(5);
	camera = sceneMgr->createCamera("camera");
	camera->setNearClipDistance(5);
    Ogre::Viewport* vp = window->addViewport(guiCamera);
    vp->setBackgroundColour(Ogre::ColourValue(0.2f,0.2f,0.8f));

	/* ambient light */
	sceneMgr->setAmbientLight(Ogre::ColourValue(0.8, 0.8, 0.8));
	sceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);

	/* meshes */
	Ogre::Entity* ent = sceneMgr->createEntity( "BouwPlaatsEntity", "world.mesh" );
	Ogre::SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode("BouwNode", Ogre::Vector3(0, 0, 0));
    node->attachObject(ent);
	//node->setScale(Ogre::Vector3(0.7,0.7,0.7));

	ent = sceneMgr->createEntity("plaats", "bouwplaats_step_00.mesh");
	Ogre::Vector3 size = ent->getBoundingBox().getSize();
	Ogre::LogManager::getSingletonPtr()->getDefaultLog()->logMessage(Ogre::String("Bouwplaats size: ") + Ogre::StringConverter::toString(size));
	size = ent->getBoundingBox().getMaximum();
	Ogre::LogManager::getSingletonPtr()->getDefaultLog()->logMessage(Ogre::String("Bouwplaats max: ") + Ogre::StringConverter::toString(size));
	size = ent->getBoundingBox().getMinimum();
	Ogre::LogManager::getSingletonPtr()->getDefaultLog()->logMessage(Ogre::String("Bouwplaats min: ") + Ogre::StringConverter::toString(size));

    Ogre::Entity* ent1 = sceneMgr->createEntity( "KeetEntity", "keet.mesh" );
	Ogre::SceneNode* scenenode = sceneMgr->getRootSceneNode()->createChildSceneNode("KeetNode", Ogre::Vector3(0, 0, 0));
    scenenode->attachObject(ent1);

	
	Ogre::Entity* ent2 = sceneMgr->createEntity( "HekjeEntity", "hekje.mesh" );
	Ogre::SceneNode* scenenode2 = sceneMgr->getRootSceneNode()->createChildSceneNode("HekjeNode", Ogre::Vector3(0, -100, 0));
    scenenode2->attachObject(ent2);
	scenenode2->setScale(Ogre::Vector3(400,0,100));

	// most examples get the viewport size to calculate this; for now, we'll just 
	// set it to 4:3 the easy way
	camera->setAspectRatio((Ogre::Real)1.333333);
	camera->setPosition(Ogre::Vector3(40,100,10));
	guiCamera->setPosition(0, 0, 300);
	guiCamera->lookAt(node->getPosition());

	// this next bit is for the sake of the input handler
	unsigned long hWnd;
	window->getCustomAttribute("WINDOW", &hWnd);

	
	// set up the input handlers
	Simulation *sim = new Simulation();
	InputHandler *handler = new InputHandler(sim, hWnd, camera);
	DataManager *dataManager = new DataManager();
	GameAI* gameAI = new GameAI(dataManager);

	//Create Network
	Network * net = new Network(dataManager);
	//net->start();

	sim->requestStateChange(GUI);
	gui = new GuiManager();

	// networkshit
	while(!net->isConnected())
	{
		Sleep(1000);
	}
	net->Send(GETGROUPS, "", "", NULL);
	net->Send(LOGIN, "gast", "gast", 1);

	gui->setSimulation(sim);
	gui->init("", ogre, guiSceneMgr, window);
	gui->activate("main");
	handler->setWindowExtents(1024,768);
	
	SimulationState cState;
	Ogre::WindowEventUtilities::addWindowEventListener(window, handler);

	DWORD tFrameStart = 0x0; //in miliseconds
	signed long tFrameX = 0x0;
	float tDelta2 = 0.0f; //in seconds
	float m_fps = 60.0f;
	tFrameStart = GetTickCount();

	float tDelta;

	//testAI->calculateNextPath(40,10);

	while ((cState = sim->getCurrentState()) != SHUTDOWN) {

		tFrameX = GetTickCount() - tFrameStart;
		tDelta2 = (float)tFrameX / 1000.0f;
		if (tDelta2 > 3600) // tDelta > 1 hour
			tDelta2 = 1.0f / m_fps; //< System tick count has highly likely overflowed, so get approximation
		tFrameStart = GetTickCount();
		m_fps = (int)(1.0f / tDelta2);

		tDelta = tDelta2;

		handler->capture();
		handler->update(tDelta);
		gui->update(tDelta);

		//if (sim->getCurrentState() == SIMULATION || sim->getCurrentState() == SIMULATION_MOUSELOOK)
//			testAI->update(tDelta);

		// run the message pump (Eihort)
		Ogre::WindowEventUtilities::messagePump();

		ogre->renderOneFrame();

		if (sim->getCurrentState() != cState) {
			handler->StateSwitched(cState, sim->getCurrentState());
			switch (sim->getCurrentState()) {
				case GUI:
					window->getViewport(0)->setCamera(guiCamera);
					break;
				case SIMULATION:
					window->getViewport(0)->setCamera(camera);
					break;
			}
		}

	}

	// clean up after ourselves
	//delete testAI;
	delete sim;
	delete ogre;
	delete handler;
	delete gameAI;
	delete dataManager;

	return 0;
}
Esempio n. 14
0
bool GfxService::initialize(ParameterSet* var)
{
    Ogre::String plug;

#ifdef _DEBUG
    plug = "plugins_d.cfg";
#else
    plug = "plugins.cfg";
#endif

    mRoot = new Ogre::Root(plug,"","ogre.log");

    Ogre::LogManager::getSingleton().getDefaultLog()->setLogDetail(Ogre::LL_LOW);

    // Load resource paths from config file
    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::RenderSystemList* renderSystems = mRoot->getAvailableRenderers();
    mRenderSystem = *(renderSystems->begin());
    mRoot->setRenderSystem(mRenderSystem);

    mRenderSystem->setConfigOption("Full Screen", "No");
    mRenderSystem->setConfigOption("VSync", "No");

    std::stringstream strVideoMode;
    strVideoMode << 1024 << " x " << 768 << " @ " << 32 << "-bit colour";
    mRenderSystem->setConfigOption("Video Mode", strVideoMode.str());

    mWindow = mRoot->initialise(true, "TankStory");

    mSceneManager = mRoot->createSceneManager(  Ogre::ST_INTERIOR, "scMa" );
    mSceneManager->setAmbientLight( Ogre::ColourValue( 0.5, 0.5, 0.5) );

    mCamera = mSceneManager->createCamera("Camera");
    mCamera->setNearClipDistance(	1.0f );
    mCamera->setFOVy(Ogre::Radian(Ogre::Degree(45)));
    mCamera->setFarClipDistance( 10000.0f );
    mCamera->setPosition(0,100,100);
    mCamera->lookAt(0,0,0);

    Ogre::Viewport* viewport = mWindow->addViewport(mCamera);
    viewport->setBackgroundColour(Ogre::ColourValue(0.3f, 0.3f, 0.3f));
    mCamera->setAspectRatio( Ogre::Real(viewport->getActualWidth()) / Ogre::Real(viewport->getActualHeight()) );

    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(1);
    Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(Ogre::TFO_ANISOTROPIC);
    Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(8);

    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this);

    unsigned long wnd;
    mWindow->getCustomAttribute("WINDOW",&wnd);
    var->AddInt("HWND",wnd);
    var->AddInt("RenderWindow",(unsigned long)mWindow);

    return true;
}