感谢 OGRE-叶子,对于《Ogre 3D 1.7 Beginner's Guide》这本书我就对第一章按照 OGRE-
叶子的文档格式进行翻译了一下。具体安装说明也可见 Ogre 3D Wiki。
在构建 OGRE 范例的教程使用中,发现两处路径设置问题:
1 资源配置文件需要修改,否则在 Debug 下无法调试
ExampleApplication 中 mResourcePath = "E:/ogre/ogre_src_v1-7-2/build_win32/bin/debug/";
2 plugins_d.cfg 文件中修改位置
PluginFolder=E:/ogre/ogre_src_v1-7-2/build_win32/bin/debug/
have fun
1 Installing Ogre 3D
【 第一章 安装 Ogre 3D 引擎 】
Downloading and installing a new library are the first steps of learning about and using it.
【 想要学习并且使用 Ogre,就要先下载并安装它 】
In this chapter, we will learn about:
【 在这章,我们将会学习到: 】
* Download and install Ogre 3D
* Have our development environment working with Ogre 3D
* Create our first scene rendered by Ogre 3D
So let's get on with it.
【
* 下载并安装 Ogre 3D 引擎
* 配置好 Ogre 3D 引擎的开发环境
* 用 Ogre 3D 引擎构建第一个场景
那我们就开搞了。
】
Downloading and installing Ogre 3D
【 下载并安装 Ogre 3D 引擎 】
The first step we need to take is to install and configure Ogre 3D.
【 我们要干的第一步就是安装并配置 Ogre 3D 引擎 】
Time for action – downloading and installing Ogre 3D
【 实践时刻——下载并安装 Ogre 3D 引擎 】
We are going to download the Ogre 3D SDK and install it so that we can work with it later.
【 为了后面的使用,现在我们就要下载安装 Ogre 3D SDK 了 】
1. Go to http://www.ogre3d.org/download/sdk.
【 1.打开 http://www.ogre3d.org/download/sdk. 的链接 】
2. Download the appropriate package. If you need help picking the right package, take a look at
the next What just happened section.
【 2.下载合适的安装包。如果你对要下载哪个正确的安装包而需要帮助时,那就看看后面
的“刚刚发生了什么”这一部分 】
3. Copy the installer to a directory you would like your OgreSDK to be placed in.
【 3.把 SDK 的安装程序复制到你希望把 OgreSDK 放置的文件夹里 】
4. Double-click on the Installer; this will start a self extractor.
【 4.双击安装程序,这会启动一个自解压缩程序 】
5. You should now have a new folder
in your directory with a name similar
to
OgreSDK_vc9_v1-7-1.
【 5.现在你应该得到一个名字类似于 OgreSDK_vc9_v1-7-1 的文件夹 】
6. Open this folder. It should look similar to the following screenshot:
【 6.打开该文件夹。文件夹的内容应该像下面的截图 】
What just happened?
【 刚刚发生了什么?】
We just downloaded the appropriate Ogre 3D SDK for our system. Ogre 3D is a cross-platform
render engine, so there are a lot of different packages for these different platforms. After
downloading we extracted the Ogre 3D SDK.
【 我们刚刚只是下载了一个适合我们操作系统的 Ogre 3D SDK。Ogre 3D 引擎是一个跨平
台的渲染引擎,所以对于不同的操作系统就有不同的开发包。下载完 Ogre 3D SDK 我们解
压了它。 】
Different versions of the Ogre 3D SDK
【 不同版本的 Ogre 3D SDK 】
Ogre supports many different platforms, and because of this, there are a lot of different packages
we can download. Ogre 3D has several builds for Windows, one for MacOSX, and one Ubuntu
package. There is also a package for MinGW and for the iPhone. If you like, you can download
the source code and build Ogre 3D by yourself. This chapter will focus on the Windows pre-build
SDK and how to configure your development environment. If you want to use another operating
system, you can look at the Ogre 3D Wiki, which can be found at http://www.ogre3d.org/wiki.
The wiki contains detailed tutorials on how to set up your development environment for many
different platforms. The rest of the book is completely platform independent, so if you want to use
another development system, feel free to do so. It won't affect the content of this book besides the
configuration and conventions of your build environment.
【 Ogre 支持多种平台,正因为如此,有很多种不同的开发包供我们下载。Ogre 3D 在
Windows 有好几个版本,有一个支持 MacOSX 的版本还有一个支持 Ubuntu 的版本。而且还
提供了支持 MinGW 和 iPhone 的开发包。如果你愿意的话,你还可以下载 Ogre 的源码然后
自己手动编译 Ogre。这一章我们主要关注于预先编译的 Windows 的 SDK 和如何配置你的开
发 环 境 。 如 果 需 要 关 于 其 他 的 操 作 系 统 的 , 你 可 以 参 考 Ogre 3D Wiki , 网 址 为 :
http://www.ogre3d.org/wiki。Wiki 包含了对很多不同的平台下的 Ogre 开发环境的配置的教程。
这本书的剩余部分和使用的平台是完全独立的,所以如果你想使用其他的开发平台,随你便
啦。它不会影响到本书的内容和对编译系统的配置与约定。 】
Exploring the SDK
【 探索 SDK 】
Before we begin building the samples which come with the SDK, let's take a look at the SDK. We
will look at the structure the SDK has on a Windows platform. On Linux or MacOS the structure
might look different. First, we open the bin folder. There we will see two folders, namely, debug
and release. The same is true for the lib directory. The reason is that the Ogre 3D SDK comes with
debug and release builds of its libraries and dynamic-linked/shared libraries. This makes it
possible to use the debug build during development, so that we can debug our project. When we
finish the project, we link our project against the release build to get the full performance of Ogre
3D.
【 在我们编译 SDK 里面的示例之前,让我们先来看看 SDK。我们来看看 Windows 操作系
统上的 SDK 结构。在 Linux 和 MacOS 上可能会有所不同。首先,我们打开 bin 这个文件夹。
这里面会有两个文件夹,即 debug 和 release 文件夹。对于 lib 文件夹里面也是如此。这里面
的原因是在于 Ogre 3D SDK 对其库文件和动态链接库文件有 debug 和 release 两种编译方式。
这就使得我们可以在开发过程中使用 debug 模式来调试我们的项目。完成项目后,可以使用
release 模式来编译得到完整的 Ogre 3D 程序。 】
When we open either the debug or release folder, we will see many dll files, some cfg files, and
two executables (exe). The executables are for content creators to update their content files to the
new Ogre version, and therefore are not relevant for us.
【 不论打开 debug 或者 release 文件夹,我们都可以看到有很多的 dll 文件,一些 cfg 文件还
有两个可执行文件(exe)。可执行文件是为了把 Ogre 升级到一个新的版本,所以在此对我
们来说没有啥用处。 】
The OgreMain.dll is the most important DLL. It is the compiled Ogre 3D source code we will load
later. All DLLs with Plugin_ at the start of their name are Ogre 3D plugins we can use with Ogre
3D. Ogre 3D plugins are dynamic libraries, which add new functionality to Ogre 3D using the
interfaces Ogre 3D offers. This can be practically anything, but often it is used to add features like
better particle systems or new scene managers. What these things are will be discussed later. The
Ogre 3D community has created many more plugins, most of which can be found in the wiki. The
SDK simply includes the most generally used plugins. Later in this book, we will learn how to use
some of them. The DLLs with RenderSystem_ at
the start of their name are, surely not
surprisingly, wrappers for different render systems that Ogre 3D supports. In this case, these are
Direct3D9 and OpenGL. Additional to these two systems, Ogre 3D also has a Direct3D10,
Direct3D11, and OpenGL ES(OpenGL for Embedded System) render system.
【 OgreMain.dll 是最重要的 DLL 文件。后面编译的 Ogre 3D 程序都会用到它。所有名字以
Plugin_开头的 DLL 文件是 Ogre 3D 程序可以使用的插件。Ogre 3D 插件是使用 Ogre 3D 提
供的接口来给 Ogre 3D 添加新功能的动态链接库文件。插件可以提供任何东东,但是它常常
是用来添加一些特性例如更好的粒子系统或者新的场景管理器。这些东西后面会谈到的。
Ogre 3D 社区提供了很多的插件,大部分可以在 wiki 中找到。SDK 中只是包含了最近常用
的插件。在本书后面,我们会学习如何去使用它们。名字以 RenderSystem_开头的 DLL 文件,
不要惊讶啊,是为了封装起来针对于 Ogre 3D 所支持不同的渲染系统。在这里所指的是
Direct3D9 和 OpenGL。除了这两个系统,Ogre 3D 还支持 Direct3D10、Direct3D11 和 OpenGL
ES(支持嵌入式系统的 OpenGL)渲染系统。 】
Besides the executables and the DLLs, we have the cfg files. cfg files are config files that Ogre 3D
can load at startup. Plugins.cfg simply lists all plugins Ogre 3D should load at startup. These are
typically the Direct3D and OpenGL render systems and some additional SceneManagers.
quakemap.cfg is a config file needed when loading a level in the Quake3 map format. We don't
need this file, but a sample does.
【 除了可执行文件和 DLL 文件,还有一些 cfg 文件。所谓的 cfg 文件就是 Ogre 3D 程序可
以加载的配置文件。Plugins.cfg 列出了 Ogre 3D 程序启动时所要加载的全部的插件。这些通
常是 Direct3D 和 OpenGL 渲染系统还有一些附加的场景管理系统插件。当加载 Quake3 格式
的地图时需要 quakemap.cfg 这个配置文件。我们用不上这个文件,但是有个例子用得上。 】
resources.cfg contains a list of all resources, like a 3D mesh, a texture, or an animation, which
Ogre 3D should load during startup. Ogre 3D can load resources from the file system or from a
ZIP file. When we look at resources.cfg, we will see the following lines:
【 resources.cfg 包含了所有的资源的列表,例如一个 3D 网格模型、或者一个 Ogre 3D 程序
启动时的动画。Ogre 3D 程序可以从文件系统或者一个 ZIP 压缩文件中加载资源。我们如果
看看这个 resources.cfg 文件内容就可以得到以下几行: 】
Zip=../../media/packs/SdkTrays.zip
FileSystem=../../media/thumbnails
Zip= means that the resource is in a ZIP file and FileSystem= means that we want to load the
contents of a folder. resources.cfg makes it easy to load new resources or change the path to
resources, so it is often used to load resources, especially by the Ogre samples. Speaking of
samples, the last cfg file in the folder is samples.cfg. We don't need to use this cfg file. Again, it's a
simple list with all the Ogre samples to load for the SampleBrowser. But we don't have a
SampleBrowser yet, so let's build one.
【 ZIP=意味着那些资源文件是存在 ZIP 压缩包里的,FileSystem=意味着要加载一个文件夹
里的内容。resources.cfg 使得加载新的资源和改变资源的路径非常容易,所以它常常被用来
加载资源,特别是被 Ogre 的例子程序所使用。来说一下示例程序,文件夹中的最后一个 cfg
文件是 sample.cfg。我们自己用不上这个文件。其实它包含着一个 SampleBrowser(示例浏
览器)程序所需加载的所有 Ogre 示例列表。但是我们还没搞到 SampleBrowser,所以就要
搞一个出来。 】
The Ogre 3D samples
【 Ogre 3D 示例程序 】
Ogre 3D comes with a lot of samples, which show all the kinds of different render effects and
techniques Ogre 3D can do. Before we start working on our application, we will take a look at the
samples to get a first impression of Ogre's capabilities.
【 Ogre 3D SDK 附带了很多的示例,这些示例展示了不同种类的渲染效果和 Ogre 3D 技术。
在我们开始编写我们自己的程序之前,为了加深 Ogre 程序的功能我们先来看看这些示例。】
Time for action – building the Ogre 3D samples
【 实践时刻——构建 Ogre 3D 示例程序 】
To get a first impression of what Ogre 3D can do, we will build the samples and take a look at
them.
1. Go to the Ogre3D folder.
2. Open the Ogre3d.sln solution file.
3. Right-click on the solution and select Build Solution.
4. Visual Studio should now start building the samples. This might take some time, so get yourself
a cup of tea until the compile process is finished.
5. If everything went well, go into the Ogre3D/bin folder.
6. Execute the SampleBrowser.exe.
7. You should see the following on your screen:
【 为了先看看 Ogre 3D 到底能干嘛,我们会构建示例程序并且看看它们。
1. 找到 Ogre3D 的文件夹
2. 打开 Ogre3d.sln 解决问题方案文件
3. 在解决问题方案上右键选择“构建解决问题方案”
4. Visual Studio 会构建示例程序,这会消耗掉一些时间,所以在编译没有完成之前最好是
泡上杯茶喝喝
5. 若一切顺利,找到 Ogre3D/bin 文件夹
6. 运行 SampleBrowser.exe.
7. 然后你应该看到如下给力的结果: 】
8. Try the different samples to see all the nice features Ogre 3D offers.
【 8.试试运行不同的示例程序来看看 Ogre 3D 带来的精彩的特效。 】
What just happened?
【 刚刚发生了什么?】
We built the Ogre 3D samples using our own Ogre 3D SDK. After this, we are sure to have a
working copy of Ogre 3D.
【 我们使用自己的 Ogre 3D SDK 构建出 Ogre 3D 示例。在此之后,我们会有一个 Ogre 3D
开发的副本 】
Pop quiz – which post effects are shown in the samples
【 突击测验——示例程序里展示了哪些后期效果 】
1. Name at least five different post effects that are shown in the samples.
a. Bloom, Glass, Old TV, Black and White, and Invert
b. Bloom, Glass, Old Monitor, Black and White, and Invert
c. Boom, Glass, Old TV, Color, and Invert
【 1.列举至少 5 种在示例程序中展示了的不同后期效果
a. 模糊,玻璃特效,旧电视感觉,黑白效果和倒置
b. 模糊,玻璃特效,旧显示器感觉,黑白效果和倒置
c. 模糊,玻璃特效,旧电视感觉,颜色和倒置 】
The first application with Ogre 3D
【 第一个 Ogre 3D 程序 】
In this part, we will create our first Ogre 3D application, which will simply render one 3D model.
【 在这一部分,我们会创建一个只有一个 3D 模型的 Ogre 3D 程序。 】
Time for action – starting the project and configuring the IDE
【 实践时刻——创建项目并配置 IDE(集成开发环境)】
As with any other library, we need to configure our IDE before we can use it with Ogre 3D.
1. Create a new empty project.
2. Create a new file for the code and name it main.cpp.
3. Add the main function:
int main (void)
{
return 0;
}
4. Include ExampleApplication.h at the top of the following source file:
#include "Ogre\ExampleApplication.h":
5. Add PathToYourOgreSDK\include\ to the include path of your project.
6. Add PathToYourOgreSDK\boost_1_42 to the include path of your project.
7. Add PathToYourOgreSDK\boost_1_42\lib to your library path.
8. Add a new class to the main.cpp.
class Example1 : public ExampleApplication
{
public:
void createScene()
{
}
};
9. Add the following code at the top of your main function:
Example1 app;
app.go();
10. Add PathToYourOgreSDK\lib\debug to your library path.
11. Add OgreMain_d.lib to your linked libraries.
12. Add OIS_d.lib to your linked libraries.
13. Compile the project.
14. Set your application working directory to PathToYourOgreSDK\bin\debug.
15. Start the application. You should see the Ogre 3D Setup dialog.
【 由于用到了其他的一些库,在使用 Ogre 3D SDK 之前我们需要配置 IDE
1. 新建一个空工程
2. 在工程里新建一个文件,命名为 main.cpp
3. 添加一个 main 方法:
int main (void)
{
return 0;
}
4. 在该文件开头部分包含上 ExampleApplication.h 文件:
#include "Ogre\ExampleApplication.h"
5. 添加“你的 Ogre SDK 路径\include\”到你的项目 include path(头文件路径)
6. 添加“你的 Ogre SDK 路径\boost_1_42\”到你的项目 include path(头文件路径)
7. 添加“你的 Ogre SDK 路径\boost_1_42\lib\”到你的项目 lib path(库文件路径)
8. 向 main.cpp 里添加一个类:
class Example1 : public ExampleApplication
{
public:
void createScene()
{
}
};
9. 把下面的代码添加到你的 main 函数里:
Example1 app;
app.go();
10. 添加“你的 Ogre SDK 路径\ lib\debug\”到你的项目 lib path(库文件路径)
11. 添加 OgreMain_d.lib 到需要的链接库(工程属性的 Linker->Input)里
12. 添加 OIS_d.lib 到需要的链接库(工程属性的 Linker->Input)里
13. 编译此项目