我这个人记性不好,学过的东西老是爱忘,学得越多忘得越快,脑子和我可怜的硬盘一样容量比较小,所以我发现我不得不把有些东西记录下来。其实学一样东西关键在于多学多用,有道是书读百遍其意自现,对于我这种比较笨又没天赋的人来说可谓金玉良言了。
以上算前言吧,下边才是正文。
Ogre这个引擎的效率不知道实际应用起来如何,但是听说结构倒是比较好的。选择它来学习主要是因为它开源,而且是C++和Dx写的,关键还有资料比较多,国内研究的也比较多,也有一些教程,不过Ogre不断推出新版本,许多教程都有点过期了。要了解最新的使用方法还得看官方的教程。我也是直接看官方的教程,但是英文一般,每次打开大片英文页面看着的确比较迷糊,所以我打算把里面一些重要的关键部分节选出来以备参考,有时候可以快速的重温,比如这篇要介绍的如何配置Ogre,需要记吗?程序员记不了那么多啦,用的时候再查。当然Ogre也在持续更新,如果我个人还在持续学习使用Ogre,那么我也会持续更新这些教程的,如果你是Ogre的使用者记得来我的Blog:http://www.cppblog.com/singohgod 看看吧,希望能对大家有点帮助。
首先安装SDK,可以编译里面带的示例看看一些效果展示。编译源码就得下载源码吧,记得还要下一个Dependencies,解压到源码目录就可以了,编译应该能通过的,我这里没有遇到问题。
不要被繁多的目录和文件吓着了,其实运行Ogre程序只需要下列库和文件:
OGRE Libraries & Files
- OGRE libraries (OgreMain[_d].dll, OgrePlatform[_d].dll or libOgreMain.so, libOgrePlatform.so for linux).
- plugins.cfg - Text file specifying the rendering libraries available to Ogre (ie DX9, OpenGL).
- All the plugin libraries listed in plugins.cfg (you can remove items from plugins.cfg if you don't wish to use them).
- resources.cfg - If using the ExampleApplication, a text file specifing paths to materials, textures, models, etc.
- OgreCore.zip - Ensure resources.cfg has the proper path to this file if you plan to use the OGRE debug panel or profiler.
- Other Resources used in your program (*.zip; *.png; *.particle; *.mesh; ...).
还需要其他的第三方库:
These are required:
- Zlib: zlib1.dll; libz.so (debian: zlib1g, zlib1g-dev)
- DevIL: devil.dll, ilu.dll, ilut.dll; libIL.so, libILU.so (debian: libdevil1, libdevil-dev)
These are optional:
- CEGUI: OgreGUIRenderer[_d].dll, CEGUIBase[_d].dll, CEGUITaharezLook[_d].dll, CEGUIWindowsLook[_d].dll, xerces-c_2_5_0.dll
- CEGUI: libCEGUIBase.so, libCEGUIOgreRenderer.so, libxerces-c.so (debian: libcegui-mk2-0, libcegui-mk2-dev, libxerces26, libxerces26-dev)
- Cg: cg.dll; libCg.so (debian: nvidia-cg-toolkit)
- OpenEXR: openexr.dll??; (debian: libopenexr-dev libopenexr2 )
- ReferenceApp: ReferenceAppLayer.dll
不同的编译器还需要有:
Extras for Microsoft Visual C++ 6 (SP3+)
- stlport_vc6[_stldebug]46.dll
- msvcp60[D].dll
- msvcrt[D].dll
- Extras for Microsoft Visual C++.Net 2002
- stlport_vc7[_stldebug]46.dll
- msvcp70[d].dll
- msvcr70[d].dll
- Extras for Microsoft Visual C++.Net 2003
- msvcp71[d].dll
- msvcr71[d].dll
- Extras for Mingw + STLPort
- libstlport[stlg].5.0.dll
- mingwm10.dll
设置环境变量:
If you downloaded and installed the precompiled OGRE SDK, you should already have an environment variable called 'OGRE_HOME' registered already, pointing at the folder where you installed. If it isn't there you probably installed under a different user, so define OGRE_HOME manually
If you downloaded the source distribution, you should register a new environment variable OGRE_SRC pointing at the 'ogrenew' folder from the OGRE source
Ogre源码项目的目录结构:
work_dir
include
*.h
src
*.cpp
scripts
*.vcproj
新建项目也依据这个结构,你的项目应该有这些文件夹:'bin', 'include', 'media', 'testsolution', 'scripts', and 'src'
修改新项目的属性:
Debugging : Working Directory = ..\bin\Debug
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 (OgreMain.lib in Release)
如果你是安装SDK:
C/C++ : General : Additional Include Directories = ..\include;$(OGRE_HOME)\include;$(OGRE_HOME)\samples\include
Linker : General : Additional Library Directories = $(OGRE_HOME)\lib
如果你是编译源码:
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
这些设置好以后你就可以新建一个SampleApp.cpp文件,然后拷贝如下代码:
#include "ExampleApplication.h"
// Declare a subclass of the ExampleFrameListener class
class MyListener : public ExampleFrameListener
{
public:
MyListener(RenderWindow* win, Camera* cam) : ExampleFrameListener(win, cam)
{
}
bool frameStarted(const FrameEvent& evt)
{
return ExampleFrameListener::frameStarted(evt);
}
bool frameEnded(const FrameEvent& evt)
{
return ExampleFrameListener::frameEnded(evt);
}
};
// Declare a subclass of the ExampleApplication class
class SampleApp : public ExampleApplication
{
public:
SampleApp()
{
}
protected:
// Define what is in the scene
void createScene(void)
{
// put your scene creation in here
}
// Create new frame listener
void createFrameListener(void)
{
mFrameListener = new MyListener(mWindow, mCamera);
mRoot->addFrameListener(mFrameListener);
}
};
#ifdef __cplusplus
extern "C" {
#endif
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
#else
int main(int argc, char **argv)
#endif
{
// Instantiate our subclass
SampleApp myApp;
try {
// ExampleApplication provides a go method, which starts the rendering.
myApp.go();
}
catch (Ogre::Exception& e) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "Exception:\n";
std::cerr << e.getFullDescription().c_str() << "\n";
#endif
return 1;
}
return 0;
}
#ifdef __cplusplus
}
#endif
未完!
posted on 2006-07-18 12:09
大宝天天见 阅读(2332)
评论(0) 编辑 收藏 引用 所属分类:
4.2D/3D Engine