標籤:
提要
環境:
Windows8.1
VS2013
Ogre1.10 stable
cmake 3.1.1
DXSDK Download
Dependencies Download
編譯
編譯其實比較簡單。
提前裝好CMake,DXSDK。
去這裡下載1.10的源碼,解壓,建立一個build檔案夾,源碼開啟CMake,將CMakeList.txt拖到介面上,將剛才的build檔案夾設為目標檔案夾。
有個Free type的目錄需要手動設定一下。順利的話Configure -> Generate就ok了。
進入build目錄,開啟vs工程,將ALL_BUILD設定為活動工程,Debug模式和Release模式都編譯一遍。
最後運行Sample Browser。
1.8版本和1.9版本的源碼編譯出來的程式無法顯示文字,目測是Windows8 + VS2013上的個bug。
所有都編譯之後,添加個OGRE_HOME環境變數,設定為Ogre源碼的目錄,後面工程設定比較方便。
載入Tutorial Application
跑這個Debug de了三天 - -.
Tutorial Application 是Ogre官網的一個學習編程架構,首先去下載 Ogre Wiki Tutorial Framework 1.10 - (Windows line endings)
在VS2013中建立一個Win32項目
選Win32項目,勾選空的項目,一直下一步就可以了。
將解壓好的檔案添加到工程中去,最後像這樣
接下來要配置下編譯類型,由於Ogre編譯的是64位的,所以這裡也只能編譯64位的項目,右擊項目,組態管理員,添加一個x64的選項。
項目上右擊添加包含目錄
嫌難一個個打的話,直接粘下面的就可以。
$(OGRE_HOME)\OgreMain\include;$(OGRE_HOME)\build\include;$(OGRE_HOME)\build\Dependencies\include;$(OGRE_HOME)\build\Dependencies\include\freetype2;$(OGRE_HOME)\build\Dependencies\include\OIS;$(OGRE_HOME)\build\Dependencies\include\Cg;$(OGRE_HOME)\build\Dependencies;$(OGRE_HOME)\OgreMain\include\Threading;$(OGRE_HOME)\Samples\Common\include;$(OGRE_HOME)\Components\RTShaderSystem\include;$(OGRE_HOME)\Components\Overlay\include;$(OGRE_HOME)\Samples\Shadows\include;%(AdditionalIncludeDirectories)
接下來是添加連結庫
Debug模式下要連結的庫
OIS_d.lib;OgreMain_d.lib;OgreOverlay_d.lib;%(AdditionalDependencies)
Release模式下要串連的庫
OIS.lib;OgreMain.lib;OgreOverlay.lib;%(AdditionalDependencies)
設定調試環境,這樣就不用拷貝dll了,配置屬性->調試->環境。
debug模式設定為編譯出的debug庫的目錄
path=D:\VCWorkspace\ogre_1_9_0\build\bin\debug
release模式設定為編譯出的release庫的目錄
path=D:\VCWorkspace\ogre_1_9_0\build\bin\release
將X:\Path\of\Ogre\build\bin\debug下的
resources_d.cfg
plugins_d.cfg
和X:\Path\of\Ogre\build\bin\release下的
resources.cfg
plugins.cfg
拷貝到工程源碼目錄。
在TutorialApplication.cpp中添加一些代碼
void TutorialApplication::createScene(void){mSceneMgr->setAmbientLight(Ogre::ColourValue(1.0f, 1.0f, 1.0f));Ogre::Entity* sinbadEnt = mSceneMgr->createEntity("sinbad.mesh");Ogre::SceneNode* sinbadSNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();sinbadSNode->attachObject(sinbadEnt);}
就是在情境中添加sinbad.
編譯運行,順利的話就跑起來了,像這樣。
遇到的一些問題
Release模式下
OGRE EXCEPTION(6:FileNotFoundException): Cannot locate resource DualQuaternion_Common.glsl in resource group Popular or any other group. in ResourceGroupManager::openResource at ..\..\..\..\OgreMain\src\OgreResourceGroupManager.cpp
shader資源沒有添加,resources.cfg裡添加
[Popular]FileSystem=D:/VCWorkspace/ogre_1_9/Samples/Media/materials/programs/GLSL
fatal error LNK1112: 模組電腦類型“X86”與目標電腦類型“x64”衝突
工程設定不對,Ogre編譯的是64位的,工程師32位的,參考這個設定一下:
fatal error LNK1112: 模組電腦類型“X86”與目標電腦類型“x64”衝突——我的解決方案
No options available in OGRE Engine Rendering Setup.
配置視窗沒有渲染系統選項。
確定目錄下面有plugins.cfg檔案,且裡面有
Plugin=RenderSystem_Direct3D9 Plugin=RenderSystem_Direct3D11 Plugin=RenderSystem_GL
添加運行終端,列印debug資訊。
修改TutorialApplication.cpp
AllocConsole(); // Create application object TutorialApplication app; try { app.go(); } catch(Ogre::Exception& e) {#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 MessageBox(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);#else std::cerr << "An exception has occurred: " << e.getFullDescription().c_str() << std::endl;#endif }FreeConsole();
Release模式運行正常,Debug模式崩潰,記憶體不能為讀。
這種錯誤最坑,根本找不到錯在哪,打斷點都不好使。
一點點列印輸出慢慢跟,終於發現 #ifdef _DEBUG後面的代碼沒有運行。
正常情況下,debug模式會定義 _DEBUG宏,但是這次沒有!
手動添加, Debug模式下,配置屬性 -> C/C++->前置處理器->前置處理器定義,添加個_DEBUG
全世界都安靜了....
參考
Setting Up An Application With Visual Studio - http://www.ogre3d.org/tikiwiki/Setting+Up+An+Application+-+Visual+Studio
fatal error LNK1112: 模組電腦類型“X86”與目標電腦類型“x64”衝突——我的解決方案 - http://blog.csdn.net/tfy1028/article/details/8660823
OGRE之第一個程式 - http://blog.csdn.net/beyond_ray/article/details/25742969#reply
Windows編譯Ogre1.10