我這個人記性不好,學(xué)過的東西老是愛忘,學(xué)得越多忘得越快,腦子和我可憐的硬盤一樣容量比較小,所以我發(fā)現(xiàn)我不得不把有些東西記錄下來。其實(shí)學(xué)一樣?xùn)|西關(guān)鍵在于多學(xué)多用,有道是書讀百遍其意自現(xiàn),對于我這種比較笨又沒天賦的人來說可謂金玉良言了。
以上算前言吧,下邊才是正文。
Ogre這個引擎的效率不知道實(shí)際應(yīng)用起來如何,但是聽說結(jié)構(gòu)倒是比較好的。選擇它來學(xué)習(xí)主要是因為它開源,而且是C++和Dx寫的,關(guān)鍵還有資料比較多,國內(nèi)研究的也比較多,也有一些教程,不過Ogre不斷推出新版本,許多教程都有點(diǎn)過期了。要了解最新的使用方法還得看官方的教程。我也是直接看官方的教程,但是英文一般,每次打開大片英文頁面看著的確比較迷糊,所以我打算把里面一些重要的關(guān)鍵部分節(jié)選出來以備參考,有時候可以快速的重溫,比如這篇要介紹的如何配置Ogre,需要記嗎?程序員記不了那么多啦,用的時候再查。當(dāng)然Ogre也在持續(xù)更新,如果我個人還在持續(xù)學(xué)習(xí)使用Ogre,那么我也會持續(xù)更新這些教程的,如果你是Ogre的使用者記得來我的Blog:http://www.shnenglu.com/singohgod?看看吧,希望能對大家有點(diǎn)幫助。
首先安裝SDK,可以編譯里面帶的示例看看一些效果展示。編譯源碼就得下載源碼吧,記得還要下一個Dependencies,解壓到源碼目錄就可以了,編譯應(yīng)該能通過的,我這里沒有遇到問題。
不要被繁多的目錄和文件嚇著了,其實(shí)運(yùn)行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
設(shè)置環(huán)境變量:
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源碼項目的目錄結(jié)構(gòu):
work_dir
??? include
?????? *.h
??? src
?????? *.cpp
??? scripts
?????? *.vcproj
新建項目也依據(jù)這個結(jié)構(gòu),你的項目應(yīng)該有這些文件夾:'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
這些設(shè)置好以后你就可以新建一個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
大寶天天見 閱讀(2343)
評論(0) 編輯 收藏 引用 所屬分類:
4.2D/3D Engine