示例#1
0
文件: OgreSetup.cpp 项目: sajty/ember
void OgreSetup::parseWindowGeometry(Ogre::ConfigOptionMap& config, unsigned int& width, unsigned int& height, bool& fullscreen) {
	auto opt = config.find("Video Mode");
	if (opt != config.end()) {
		Ogre::String val = opt->second.currentValue;
		Ogre::String::size_type pos = val.find('x');
		if (pos != Ogre::String::npos) {

			width = Ogre::StringConverter::parseUnsignedInt(val.substr(0, pos));
			height = Ogre::StringConverter::parseUnsignedInt(val.substr(pos + 1));
		}
	}

	//now on to whether we should use fullscreen
	opt = config.find("Full Screen");
	if (opt != config.end()) {
		fullscreen = (opt->second.currentValue == "Yes");
	}

}
bool OgreFramework::initOgre(Ogre::String wndTitle, HWND hwnd)
{
    if (!hwnd)
    {
        return false;
    }

    _hWnd = hwnd;

#if _DEBUG
    m_pRoot = new Ogre::Root("plugins_d.cfg", "Ogre.cfg");
#else
    m_pRoot = new Ogre::Root("plugins.cfg", "Ogre.cfg");
#endif

//#if _DEBUG
//
//	m_pRoot->loadPlugin("RenderSystem_Direct3D9_d");
//	m_pRoot->loadPlugin("Plugin_ParticleFX_d");
//	//m_pRoot->loadPlugin("Plugin_CgProgramManager_d");
//
//#else
//
//	m_pRoot->loadPlugin("RenderSystem_Direct3D9");
//	m_pRoot->loadPlugin("Plugin_ParticleFX");
//	//m_pRoot->loadPlugin("Plugin_CgProgramManager");
//
//#endif

    if (!m_pRoot->restoreConfig())
    {
        //m_pRoot->showConfigDialog();

        RenderSystemList rList = m_pRoot->getAvailableRenderers();
        if (rList.size() == 0)
            return false;

        m_pRoot->setRenderSystem( *(rList.begin()) );

        try
        {
            m_pRoot->saveConfig();	//crash on windows vista or above if no administrator right
        }
        catch (...)
        {

        }
    }

    m_pRenderWnd = m_pRoot->initialise(false, wndTitle);

    Ogre::ConfigOptionMap	optionMap = m_pRoot->getRenderSystem()->getConfigOptions();
    if (optionMap.find("FSAA") != optionMap.end())
    {
        _strFSAA = optionMap["FSAA"].currentValue;
    }

    NameValuePairList opts;
    opts["externalWindowHandle"] = StringConverter::toString((Ogre::uint)_hWnd);
    //opts["vsync"]	= "true";
    opts["FSAA"]	= _strFSAA;

    m_pRenderWnd = m_pRoot->createRenderWindow(
                       wndTitle,
                       800, 600,
                       false, &opts
                   );


    m_pSceneMgr = m_pRoot->createSceneManager(ST_GENERIC, "SceneManager");
    m_pSceneMgr->setAmbientLight(Ogre::ColourValue(0.7f, 0.7f, 0.7f));


    m_pCamera = m_pSceneMgr->createCamera("Camera");
    m_pCamera->setPosition(Vector3(0, 120, 120));
    m_pCamera->lookAt(Vector3(0, 0, 0));
    m_pCamera->setNearClipDistance(1);

    _pCameraController = new CameraController(m_pCamera);


    m_pViewport = m_pRenderWnd->addViewport(m_pCamera);
    m_pViewport->setBackgroundColour(ColourValue(0.0f, 0.0f, 0.0f, 1.0f));
    m_pCamera->setAspectRatio(Real(m_pViewport->getActualWidth()) / Real(m_pViewport->getActualHeight()));
    m_pViewport->setCamera(m_pCamera);


    OIS::ParamList paramList;
    unsigned long hWnd = (unsigned long)AfxGetMainWnd()->GetSafeHwnd();
    //m_pRenderWnd->getCustomAttribute("WINDOW", &hWnd);
    paramList.insert(OIS::ParamList::value_type("WINDOW", Ogre::StringConverter::toString(hWnd)));
    paramList.insert(OIS::ParamList::value_type("w32_mouse", "DISCL_FOREGROUND"));
    paramList.insert(OIS::ParamList::value_type("w32_mouse", "DISCL_NONEXCLUSIVE"));
    paramList.insert(OIS::ParamList::value_type("w32_keyboard", "DISCL_FOREGROUND"));
    paramList.insert(OIS::ParamList::value_type("w32_keyboard", "DISCL_NONEXCLUSIVE"));
    m_pInputMgr = OIS::InputManager::createInputSystem(paramList);


    m_pKeyboard = static_cast<OIS::Keyboard*>(m_pInputMgr->createInputObject(OIS::OISKeyboard, true));
    m_pKeyboard->setEventCallback(this);

    m_pMouse	= static_cast<OIS::Mouse*>(m_pInputMgr->createInputObject(OIS::OISMouse, true));
    m_pMouse->setEventCallback(this);

    m_pMouse->getMouseState().height = m_pRenderWnd->getHeight();
    m_pMouse->getMouseState().width	 = m_pRenderWnd->getWidth();

    Ogre::String secName, typeName, archName;
    Ogre::ConfigFile cf;
    cf.load("resources.cfg");

    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
    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::TextureManager::getSingleton().setDefaultNumMipmaps(5);
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    m_pTimer = new Ogre::Timer();
    m_pTimer->reset();

    m_pTrayMgr = new OgreBites::SdkTrayManager("TrayMgr", m_pRenderWnd, m_pMouse, this);
    //m_pTrayMgr->showFrameStats(OgreBites::TL_BOTTOMLEFT);
    //m_pTrayMgr->showLogo(OgreBites::TL_BOTTOMRIGHT);
    m_pTrayMgr->hideCursor();

    m_pRenderWnd->setActive(true);


    /*
    BaseProperty *pProp = GetClassRTTI()->GetPropertyByName("FSAA");
    Ogre::ConfigOptionMap	optionMap = m_pRoot->getRenderSystem()->getConfigOptions();
    Ogre::StringVector		fsaaVector = optionMap["FSAA"].possibleValues;
    Ogre::String			strOpts;
    for (size_t t = 0; t < fsaaVector.size(); ++t)
    {
    	strOpts += fsaaVector[t];

    	if (t != fsaaVector.size() - 1)
    	{
    		strOpts += ";";
    	}
    }
    pProp->SetValueSpecify(eValueList, strOpts);
    */


    return true;
}