Windows编译Ogre1.10

发表于2017-09-11
评论0 1.8k浏览

提要

环境:

Windows8.1 

VS2013

Ogre1.10 stable

cmake 3.1.1

DXSDK

Dependencies


编译

编译其实比较简单。

提前装好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的选项。



项目上右击添加包含目录


嫌难一个个打的话,直接粘下面的就可以。

  1. $(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模式下要链接的库

  1. OIS_d.lib;OgreMain_d.lib;OgreOverlay_d.lib;%(AdditionalDependencies)  


Release模式下要连接的库 copy
  1. OIS.lib;OgreMain.lib;OgreOverlay.lib;%(AdditionalDependencies)  

设置调试环境,这样就不用拷贝dll了,配置属性->调试->环境。

debug模式设置为编译出的debug库的目录

  1. path=D:\VCWorkspace\ogre_1_9_0\build\bin\debug  

release模式设置为编译出的release库的目录
  1. 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中添加一些代码 copy

  1. void TutorialApplication::createScene(void)  
  2. {  
  3.     mSceneMgr->setAmbientLight(Ogre::ColourValue(1.0f, 1.0f, 1.0f));  
  4.     Ogre::Entity* sinbadEnt = mSceneMgr->createEntity("sinbad.mesh");  
  5.     Ogre::SceneNode* sinbadSNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();  
  6.     sinbadSNode->attachObject(sinbadEnt);  
  7. }  

就是在场景中添加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里添加

  1. [Popular]  
  2. 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文件,且里面有

  1. Plugin=RenderSystem_Direct3D9  
  2. Plugin=RenderSystem_Direct3D11  
  3. Plugin=RenderSystem_GL  


添加运行终端,打印debug信息。

修改TutorialApplication.cpp

  1.         AllocConsole();  
  2.   
  3.         // Create application object  
  4.         TutorialApplication app;  
  5.   
  6.         try {  
  7.             app.go();  
  8.         } catch(Ogre::Exception& e)  {  
  9. #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32  
  10.             MessageBox(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);  
  11. #else  
  12.             std::cerr << "An exception has occurred: " <<  
  13.                 e.getFullDescription().c_str() << std::endl;  
  14. #endif  
  15.         }  
  16.     FreeConsole();  


error LNK2019: 无法解析的外部符号 __imp___CrtDbgReportW 

this kind error, just need change the C/C ->code generation-> runtime library "Multi-threaded Debug (/MTd)" ->Multi-threaded Debug DLL (/MDd)

Release模式运行正常,Debug模式崩溃,内存不能为读。

这种错误最坑,根本找不到错在哪,打断点都不好使。

一点点打印输出慢慢跟,终于发现 #ifdef _DEBUG后面的代码没有运行。

正常情况下,debug模式会定义 _DEBUG宏,但是这次没有!

手动添加, Debug模式下,配置属性 -> C/C ->预处理器->预处理器定义,添加个_DEBUG


全世界都安静了....

如社区发表内容存在侵权行为,您可以点击这里查看侵权投诉指引