天天看点

Ogre源码在VS2005(VC8)中的配置方式

Ogre源码在VS2005(VC8)中的配置方式

(参照 Ogre源码在VS2008(VC9)中的配置方式 此文所写,其实配置方式都差不多,就是有些小的地方有些许不同而已。

地址:http://blog.csdn.net/zeroboundary/archive/2008/11/30/3414086.aspx)

呃,今天终于开始Ogre之旅了。

不过配置还是花了不少的时间才搞定,就是需要些耐心。

准备工作:

首先安装

1.         Microsoft Visual Studio 2005(此处使用的VS2005中文版)(开发工具,不用介绍了)注意这里必须要安装#sp1,官方网站特别强调,否则会出现未知的错误。不过大家一般使用vs2005的都会安装sp1补丁的哈。

2.         DXSDK_Aug09最新 (此处我安装在D:\Program Files\Microsoft DirectX SDK (August 2009)目录下) (完全安装大约需要1G空间)

3.         ×××地址http://www.ogre3d.org/download/source

OGRE 1.6.4 Source For Windows 27 September 2009 49.5Mb
Visual C++.Net 2005 (8.0) SP1 Precompiled Dependencies 28 December 2007 15.7Mb Please note – you must have installedVS2005 Service Pack 1. You may also be interested in the debug symbols.

参考官网上的教程:http://www.ogre3d.org/wiki/index.php/Building_From_Source#Visual_C.2B.2B_2005_.28VC8.2FSP1.29

正确操作步骤:

1.         解压 ogre-v1-6-4.zip(源码包)(请确保磁盘空间足够:正确编译后的文件总和大约是3.3G。好大哦)

2.         解压 OgreDependencies_VC8SP1_Eihort_20071227.zip

3.         将 OgreDependencies_VC8SP1_Eihort_20071227.zip解压后的两个文件夹Samples和Dependencies拷贝到 ogre目录(ogre-v1-6-4.zip(源码包)解压后的目录)下,如果提示文件或目录已存在,则直接覆盖. 注意这个非常重要,但是很容易被忽略,我就是这样。否则编译不通过的,因为这个里面有ogre需要链接的第三方库。要注意的是,ogre3D.cn貌似好久都没更新了,所以建议上ogre3D.org,也就是官网非中文网.cn寻求解决方法。

4.         双击Ogre目录下的Ogre_vc8.sln文件,即:打开Ogre源码解决方案

这里遗忘了一个步骤:

4.5.         打开 Ogre_vc9解决方案下的工程的属性页

a.         将工程属性页中的    配置属性 -> C/C++     ->    常规       ->    附加包含目录 添加:Microsoft DirectX SDK (August 2008)目录下的Include目录(Microsoft DirectX SDK (August 2008)为刚刚安装的Direct3Dsdk默认目录)

b.         将工程属性页中的    配置属性 -> 连接器    ->    常规       ->    附加库目录 添加:Microsoft DirectX SDK (August 2008)\Lib 目录下的x86目录(32位机 x64为64位机)

5.         编译整个解决方案。

6.         经过30分钟编译,整个解决方案编译成功

《========== 生成: 成功50 个,失败0 个,最新0 个,跳过0 个==========》

7.       测试下,启动ogremain实例,弹出个对话框。看看其他的实例,基本ok。但是有两三个示例貌似是有问题的。哇,可爱的食人魔。

Ogre源码在VS2005(VC8)中的配置方式

         但是貌似vs2008的还需要改些东东才能成功启动实例。vs2008可以参考: http://blog.csdn.net/zeroboundary/archive/2008/11/30/3414086.aspx)

以上就是我在vs2005下关于Ogre源码的配置方式。

接下来就是要创建第一个Ogre程序了。这个就没上面的那么顺利了,要麻烦些。

参考官网教程SettingUpAnApplication:

http://www.ogre3d.org/wiki/index.php/SettingUpAnApplication#Microsoft_Visual_C.2B.2B_.NET

其实可以简单点用:Also see The Complete Blanks Guide To Using The OGRE SDK AppWizard. 这个可以这样,但是是需建立在ogre3D SDK的。

忽略,选择手动建立Ogre程序:

1.创建一个普通'Win32空项目,创建一个新项 'Project -> Add New Item...'. 为main.cpp,从普通教程中copy个最简单的代码过来,保存,ok。

看网站教程:

To clarify where the DLL files should be, an easy way is to copy the \bin folder (containing \debug and \release) and the \media folder from the OGRE installation directory to your Testproject folder (note: in this case you might be copying DLLs that won't be needed, but it's the hassle-free way). If you follow the convention presented above and you created folders for the header, scripts and source files, you have the following folders under \Testproject (excluding subfolders): 'bin', 'include', 'media', 'testsolution', 'scripts', and 'src'. However, if you don't want to copy them while running your Testproject from Visual Studio just add the path to OGRE's DLL files to the %PATH% global environment variable like this:

Debugging : Environment                             = PATH=%PATH%;%OGRE_HOME%\bin\debug

and for the release version

Debugging : Environment                             = PATH=%PATH%;%OGRE_HOME%\bin\release

This will not modify the %PATH% environment variable permanently, just for the given run, so its safer. You could modify it globally for all windows applications like this:

My Computer -> Properties -> Advanced -> Environment Variables -> System Variables -> Path    += ;%OGRE_HOME%\bin\debug      

or

My Computer -> Properties -> Advanced -> Environment Variables -> System Variables -> Path      
呃,这段后面没怎么看懂,所以不能偷懒了,只能乖乖地最简单的实现,把上面说的那些目录copy到我刚建立的新项目目录下。暂时只能这么用,谁叫自己这么菜。      
配置项目属性:      
Debugging : Command                                 = $(OutDir)\$(ProjectName).exe
Debugging : Working Directory                       = $(OutDir)
C/C++ : Preprocessor : Preprocessor Definitions += _STLP_DEBUG (only in Debug mode, not needed for .Net 2003 and 2005)
C/C++ : Code Generation : Use runtime library   = Multithreaded Debug DLL (Multithreaded DLL in Release)
Linker : General : Output File                            = ..\bin\Debug\[appname].exe
Linker : Input : Additional Dependencies                += OgreMain_d.lib OIS_d.lib  (OgreMain.lib OIS.lib in Release)      

对应我的项目属性配置

Debugging : Command                                 = $(OutDir)\$(ProjectName).exe

Debugging : Working Directory                       = $(OutDir)

这两个都一样。

C/C++ : Preprocessor : Preprocessor Definitions += _STLP_DEBUG (only in Debug mode, not needed for .Net 2003 and 2005)

这个忽略掉note:only in Debug mode, not needed for .Net 2003 and 2005

Linker : General : Output File                            = $(OutDir)\$(ProjectName).exe 一般项目生成后默认就可以

Linker : Input : Additional Dependencies                += OgreMain_d.lib OIS_d.lib (OgreMain.lib OIS.lib in Release)

这个也一样。

C/C++ : General : Additional Include Directories   = ..\include;$(OGRE_SRC)\OgreMain\include;$(OGRE_SRC)\Samples\Common\Include
Linker : General : Additional Library Directories         = $(OGRE_SRC)\OgreMain\Lib\Debug      
呃,这里 $(OGRE_SRC) 这个环境变量不知道怎么弄呃,安装了SDK后默认环境变量中就有OGRE_HOME,这个就是OGRE的默认安装目录。      
但是源码是zip格式的,解压出来的,所以没有自动生成环境变量$(OGRE_SRC) ,在网站上找了找也没找到这个怎么生成的,所以自己就直接在环境变量下按照OGRE_HOME写一个OGRE_SRC的环境变量,      
结果是运行后说找不到***.lib ***.h 等。失败,又不能偷懒了,都怪自己太菜,哎,只能写绝对路径了:      
希望某位高手看到后能够指点下,感激不敬。。。。      
C/C++ : General : Additional Include Directories   =..\include; d:\Project\ogre-v1-6-4\ogre\OgreMain\include; d:\Project\ogre-v1-6-4\ogre\Samples\Common\Include; D:\Project\ogre-v1-6-4\ogre\Dependencies\include      
Linker : General : Additional Library Directories         =d:\Project\ogre-v1-6-4\ogre\lib;d:\Project\ogre-v1-6-4\ogre\Dependencies\lib\Debug      
发现网站上提示的目录并不是完全准确的,所以就得自己调了,缺少哪个库后在source里面找到库文件,然后把库的路径包含进去。      
最后编译通过,运行,提示ogremain.dll找不到,郁闷,dll我都全部copy过来了啊,怎么会找不到呢??晕,解决方案下有两个debug目录,放错目录了。      
ok,将dll啊什么的再又copy一份过去,继续。结果出现media目录下的*.zip文件打不开,呃目录层级有问题,放到正确的层级目录下,调试      
哇,出现了可爱食人魔头像,高兴。done。      
回头想想,不知道是不是我太菜了,弄得这么复杂一个啊。但是按照网站上的步骤其实差不多啊,就是每次都要copy 所有debug目录下的dll和media目录到新的工程目录下,真是麻烦,但是这也没办法啊,我也想偷懒啊。      
期待高手的帮忙。      
不行,想偷懒的话,还是有点方法的,就是将所有生成的exe生成目录指向sample\common\bin\debug,像Ogre提供的示例一样,都放在这个目录下,不就不要copy这些个麻烦东东过去了嘛。哈哈,begin:      
模仿Ogre_VC8.sln中的单个工程项目属性中的生成目录、包含路径、包含库。      
记录下自己的工程属性修改后的:      
输出目录:D:\Project\ogre-v1-6-4\ogre\Samples\Common\bin\$(ConfigurationName)      
中间目录:D:\Project\ogre-v1-6-4\ogre\Samples\Common\obj\$(ConfigurationName)      
命令:D:\Project\ogre-v1-6-4\ogre\Samples\Common\bin\$(ConfigurationName)\$(TargetFileName)      
工作目录:D:\Project\ogre-v1-6-4\ogre\Samples\Common\bin\$(ConfigurationName)      
c++\常规\附加包含目录:D:\Project\ogre-v1-6-4\ogre\Samples\Common\include; d:\Project\ogre-v1-6-4\ogre\OgreMain\include; d:\Project\ogre-v1-6-4\ogre\Samples\Common\Include; D:\Project\ogre-v1-6-4\ogre\Dependencies\include       
连接器\常规\附加库目录:d:\Project\ogre-v1-6-4\ogre\lib;d:\Project\ogre-v1-6-4\ogre\Dependencies\lib\Debug      
呃 用的都是绝对路径,所以这个环境变量OGRE_SCR真的很重要。      
ok,好了,编译,链接,运行,可爱的ogre头像出现了,然后在D:\Project\ogre-v1-6-4\ogre\Samples\Common\bin\Debug 目录下可以找到这个启动程序exe。      
然后就可以一边欣赏ogre源码,一边调试着自己写的代码了。开心状。。。      

继续阅读