开发环境 OGRE 1.72
本文需要熟悉MFC,本文并非原创,这里只是进行总结归纳。代码地址:
https://3dlearn.googlecode.com/svn/trunk/Samples/OgreMFC步骤
1、在CWinApp::InitInstance中完成OGRE初始化。
初始化
1#ifdef DEBUG
2 mRoot = new Ogre::Root("plugins_d.cfg", "OgreMFC.cfg", "OgreMFC.log");
3#else
4 mRoot = new Ogre::Root("plugins.cfg", "OgreMFC.cfg", "OgreMFC.log");
5#endif
6
7 //
8 // Setup paths to all resources
9 //
10
11 Ogre::ConfigFile cf;
12 cf.load("resources_d.cfg");
13
14 // Go through all sections & settings in the file
15 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 Subsystem
40 break;
41 pRend++;
42 }
43
44 if (pRend == render.end())
45 {
46 // Unrecognised render system
47 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()
5、在view中启动定时器,比便模拟主循环操作。这个定时器让窗口失效,从而驱动帧渲染。
6、在FrameListener对象中执行用户逻辑处理