OGRE嵌入MFC筆記
開發環境 OGRE 1.72本文需要熟悉MFC,本文并非原創,這里只是進行總結歸納。代碼地址:https://3dlearn.googlecode.com/svn/trunk/Samples/OgreMFC
步驟
1、在CWinApp::InitInstance中完成OGRE初始化。
1
#ifdef DEBUG2
mRoot = new Ogre::Root("plugins_d.cfg", "OgreMFC.cfg", "OgreMFC.log"); 3
#else4
mRoot = new Ogre::Root("plugins.cfg", "OgreMFC.cfg", "OgreMFC.log"); 5
#endif6

7
//8
// Setup paths to all resources9
//10

11
Ogre::ConfigFile cf;12
cf.load("resources_d.cfg");13

14
// Go through all sections & settings in the file15
ConfigFile::SectionIterator seci = cf.getSectionIterator();16

17
String secName, typeName, archName;18
while (seci.hasMoreElements())19

{20
secName = seci.peekNextKey();21
ConfigFile::SettingsMultiMap *settings = seci.getNext();22
ConfigFile::SettingsMultiMap::iterator i;23
for (i = settings->begin(); i != settings->end(); ++i)24

{25
typeName = i->first;26
archName = i->second;27
ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName);28
}29
}30

31
const RenderSystemList& render = mRoot->getAvailableRenderers();32

33
RenderSystemList::const_iterator pRend = render.begin();34

35
while (pRend != render.end())36

{37
Ogre::String rName = (*pRend)->getName();38
//if (rName == "OpenGL Rendering Subsystem") //39
if (rName == "Direct3D9 Rendering Subsystem") //Direct3D9 Rendering Subsystem40
break;41
pRend++;42
}43

44
if (pRend == render.end())45

{46
// Unrecognised render system47
AfxMessageBox("Unable to locate OpenGL rendering system. Application is terminating");48
return FALSE;49
}50

51
Ogre::RenderSystem *rsys = *pRend;52
rsys->setConfigOption("Full Screen", "No");53
rsys->setConfigOption("VSync", "Yes");54

55
// Set the rendering system.56
mRoot->setRenderSystem(rsys);57

58
//59
// Initialize the system, but don't create a render window.60
//61
mRoot->initialise(false);2、在View中完成OGRE所有相關創建操作:創建渲染窗口、創建場景管理器、創建攝像頭、創建視口、加載資源、并創建場景
3、view持有FrameListener的派生對象,這個對象真正執行場景的創建和監聽事件的回調,包括最關鍵的frameStarted
4、在view的paint消息中執行幀渲染:
renderOneFrame()6、在FrameListener對象中執行用戶邏輯處理

