• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            初始化

                   正面的這段代碼是在main()之后的初始化代碼:

            //wrangle a pointer to the Root Ogre object 
                    // the first param is the name of the plugins cfg file, the second is the name of the ogre cfg file
                    // we are not using either here, so provide them as empty strings to let Ogre know not to load them
                    // The third param is the name of the Ogre.log diagnostic file; leave it default for now
                    ogre = new Root("", "");
             
                    try {
                           ResourceGroupManager::getSingleton().addResourceLocation(
                                   "resource", "FileSystem", "General");
                           ResourceGroupManager::getSingleton().addResourceLocation(
                                   "resource/gui.zip", "Zip", "GUI");
             
                           VideoOptions opts;
                           VideoOptions::iterator it;
                           getOptions(opts);
                           std::string val;
                           unsigned int h, w;
                           bool fullscreen = false;
                           Ogre::RenderSystemList *renderSystems = NULL;
                           Ogre::RenderSystemList::iterator r_it;
             
                           val = opts.find("renderSystem")->second;
                           renderSystems = ogre->getAvailableRenderers();
             
                           // check through the list of available renderers, looking for the one that contains
                           // the string in "val" ('renderSystem' option from the config.ini file)
                           bool renderSystemFound = false;
                           for (r_it=renderSystems->begin(); r_it!=renderSystems->end(); r_it++) {
                                   RenderSystem *tmp = *r_it;
                                   std::string rName(tmp->getName());
             
                                   // returns -1 if string not found
                                   if ((int) rName.find(val) >= 0) {
                                           ogre->setRenderSystem(*r_it);
                                           renderSystemFound = true;
                                           break;
                                   }
                           }
             
                           if (!renderSystemFound) {
                                   throw new VideoInitializationException("Specified render system (" + val + ") not found, exiting...");
                           }
             
             
                           // sscanf is the easy way to do this
                           val = opts.find("resolution")->second;
                           sscanf(val.c_str(), "%dx%d", &w, &h);
                           opts.erase("resolution");
             
                           val = opts.find("fullscreen")->second;
                           if (val == "true")
                                   fullscreen = true;
                           opts.erase("fullscreen");
             
                           // false because we are not using an autocreated window
                           ogre->initialise(false);
                           window = ogre->createRenderWindow(appName, w, h, fullscreen, &opts);
             
                           ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
             
                           guiSceneMgr = ogre->createSceneManager(ST_GENERIC);
                           showGui();
                    }
                    catch (Ogre::Exception &e) {
                           std::string msg = e.getFullDescription();
                           std::cerr << msg << std::endl;
                            exit (-1);
                    }

            在這里,你不想使用默認(rèn)的對(duì)話框設(shè)置以及不想用Ogre.cfg,而想用自己的一個(gè)文件來對(duì)所有的子系統(tǒng)進(jìn)行配置. 因此,你需要手動(dòng)地處理它.不是很大的事,你只需要對(duì)STL熟悉就行了.

            ResourceGroupManager::getSingleton().addResourceLocation(
                                   "resource", "FileSystem", "General");
                           ResourceGroupManager::getSingleton().addResourceLocation(
                                   "resource/gui.zip", "Zip", "GUI");

            上面的代碼,第一個(gè)目錄”resource”,在我們游戲的安裝根目錄下.在這個(gè)系列中,我們將把所有游戲的資源數(shù)據(jù)放在游戲根目錄下.加上這個(gè)目錄可以讓Ogre ResourceGroupManager知道如何去找到我們的資源. 下一語句指明Gui資源,需要注意的是,資源不能有重名,要不然會(huì)崩潰.

                   對(duì)Ogre的資源管理子系統(tǒng)需要注意的是:1.它不會(huì)到子目錄中去尋找,因此,你必須告訴它.2.文件夾的名字是沒有意義的.這就是說,如果在不同的文件夾內(nèi),有兩個(gè)文件重名的話,也是不行的.

                   在這里,對(duì)于我們資源的加載,首先,我們沒有導(dǎo)入OgreCore.zip.因?yàn)槟悴恍枰?/span>.它對(duì)Demo是有用的.第二,我們把所有與GUI相關(guān)的內(nèi)容放在了gui.zip這個(gè)文件中.

            (對(duì)于CEGUI熟悉的用戶可能覺得這樣的配置不好,但是,這樣做的話,將來你在用CEGUI的配置的時(shí)候可以省掉很多麻煩).

            配置

                   這個(gè)章節(jié)將寫一些用于讀取config.ini的代碼.

                VideoOptions STL std::maptypedef, getOptions() 配置讀取函數(shù)返回這個(gè)值. 巧合的是, Ogre::NameValuePairList 也是這樣用的.需要記住的是,這需要你在你的.ini配置文件中使用option名字.

            在你的頭文件中,記得加入正面的typedef:

            typedef NameValuePairList VideoOptions;

            為了便于參考,正面是一個(gè)對(duì)于video section的配置文件:

            [video]
            FSAA=0
            colourDepth=32
            fullscreen=false
            renderSystem=Direct3D9
            resolution=800x600
            vsync=false

            這里選了一個(gè)默認(rèn)的D3d渲染系統(tǒng),你也可以在GUI的配置選項(xiàng)中,getAvailableRenderers()來得到所有的可用的渲染API,然后選擇使用哪一個(gè). 一旦你有了渲染系統(tǒng),你就可以創(chuàng)建主要的Ogre window.

            getOptions()是一個(gè)簡(jiǎn)單的函數(shù),其使用Win32SHGetFolderPath() APILinux中的$HOME變量和Win32 GetPrivateProfileSection()來讀配置文件的sections.這些讀出的內(nèi)容放在VideoOptions表里面.下面是getOptions()的代碼:

            #ifdef WIN32
            #include <shlobj.h>
            #else
            #endif
             
            bool getOptions(VideoOptions opts)
            {
                    // read these from the ubiquitous config file...on Win32 we have a nice handy
                    // API to read config files; on other platforms we'll need to fake one
                    char path[MAX_PATH+1];
             
            #ifdef WIN32
                    SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path);
            #else
            #endif
                    
                    std::string pathname(path);
                    pathname += "/" + CONFIG_OPTS_DIR + "/" + CONFIG_FILE_NAME;
             
            #ifdef WIN32 
                    DWORD nSize = 1024, rtnSize;
                    char strVal[1024], *cp = strVal;
             
                    // yes I know this is not the right way to handle this situation...sue me. :p
                    rtnSize = GetPrivateProfileSection("video", strVal, nSize, pathname.c_str());
                    if (rtnSize == nSize - 2)
                           throw new VideoInitializationException("Cannot read video settings - buffer too small");
                    if (rtnSize == 0)
                           return false;
             
                    std::string name, val;
             
                    opts.clear();
                    while (*cp != 0 && *(cp+1) != 0) {
                           name = cp;
                           val = cp;
                           cp += strlen(cp) + 1;
             
                           name = name.substr(0, name.find('='));
                           val = val.substr(val.find('=') + 1);
             
                           opts.insert(VideoOptions::value_type(name, val));
                    }
            #else
            #endif
             
                    return true;
            }

            Win32環(huán)境中需要添加頭文件"shlobj.h".

            CONFIG_OPTS_DIR 是你的配置文件夾的位置. CONFIG_FILE_NAME 在我們這個(gè)例子中是 "config.ini"; 在后面會(huì)看到,如果用戶沒有config.ini,我們會(huì)創(chuàng)建一個(gè)合適的默認(rèn)給它.現(xiàn)在我們用Lua腳本讀出它的配置信息

            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            posts - 15, comments - 2, trackbacks - 0, articles - 29

            Copyright © 美洲豹

            久久精品国产精品亚洲| 狠狠色综合久久久久尤物| 久久国产精品视频| 亚洲欧美日韩久久精品第一区| 亚洲午夜无码AV毛片久久| 久久精品免费全国观看国产| 亚洲а∨天堂久久精品9966| 性做久久久久久久久老女人| 精品国产青草久久久久福利| 亚洲狠狠综合久久| 无码任你躁久久久久久| 精品免费久久久久国产一区 | 7777久久亚洲中文字幕| 99久久国产亚洲高清观看2024| 国产精品久久99| 一级做a爰片久久毛片人呢| 欧美伊香蕉久久综合类网站| 久久中文字幕精品| 久久这里都是精品| 色偷偷88888欧美精品久久久| 欧美亚洲国产精品久久蜜芽| 2021少妇久久久久久久久久| 青青国产成人久久91网| 亚洲午夜久久久影院伊人| 久久国产一区二区| 国产成人久久精品激情 | 久久久WWW成人| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 精品综合久久久久久97| 精品久久久久久久久久中文字幕| 伊人久久大香线蕉影院95| 久久国产午夜精品一区二区三区| 蜜臀久久99精品久久久久久| 99久久99久久| 精品久久久久久无码人妻蜜桃| 欧美大战日韩91综合一区婷婷久久青草 | 久久夜色精品国产网站| 国产成人香蕉久久久久| 99精品国产在热久久无毒不卡 | 久久国产成人午夜AV影院| 狠狠色丁香久久婷婷综合_中 |