您的位置:首页 > 移动开发

ogre 学习笔记系列(三)启动过程 参考 ExampleApplication.h

2011-12-19 18:26 459 查看
1、入口:

/// Start the example
virtual void go(void)
{
if (!setup())
return;
/*渲染流程
1. 调用帧监听者的frameStarted()函数
2. 调用当前的渲染窗口的update()函数
a) 调用场景管理器的_renderScene()函数,它会根据当前摄像机的提供的可见对象列表,逐一渲染所有的对象。
3. 调用帧监听者的frameEnded ()函数
4. 重复1-3步,直到窗口关闭。
*/
mRoot->startRendering();

// clean up删除场景,释放资源
destroyScene();

#ifdef USE_RTSHADER_SYSTEM
// Finalize shader generator.
finalizeShaderGenerator();
#endif

}

2、setup()

// These internal methods package up the stages in the startup process
/** Sets up the application - returns false if the user chooses to abandon configuration. */
virtual bool setup(void) {

String pluginsPath;
// only use plugins.cfg if not static
#ifndef OGRE_STATIC_LIB
#if OGRE_DEBUG_MODE
pluginsPath = mResourcePath + "plugins_d.cfg";
#else
pluginsPath = mResourcePath + "plugins.cfg";
#endif
#endif
//Root对象代表了整个渲染系统,因此必须首先创建。在创建Root对象时,也会创建一个默认的Ogre.log日志文件,同时也会把所有的创建过程记录到日志文件中
mRoot = OGRE_NEW Root(pluginsPath, mConfigPath + "ogre.cfg",
mResourcePath + "Ogre.log");
#ifdef OGRE_STATIC_LIB
mStaticPluginLoader.load();
#endif

//这个函数解析资源配置文件resources.cfg,并在系统中记录所有这些资源的路径,但这时并不在内存中创建资源对应的对象。
setupResources();

bool carryOn = configure();
if (!carryOn)
return false;
//创建一个通用的场景管理器,并记录到成员变量mSceneMgr中。
chooseSceneManager();
//用于在场景管理器中创建一个摄像机,并记录到成员变量mCamer中。窗口中显示的图像就是它拍摄的图像。
createCamera();
//创建一个视口,它告诉渲染窗口在什么区域显示摄像机的图像,默认把图像显示在整个窗口区域。
createViewports();
#ifdef USE_RTSHADER_SYSTEM
// Initialize shader generator.
carryOn = initializeShaderGenerator(mSceneMgr);
if (!carryOn)
return false;
#endif

// Set default mipmap level (NB some APIs ignore this)
TextureManager::getSingleton().setDefaultNumMipmaps(5);

// Create any resource listeners (for loading screens)
createResourceListener();
//函数初始化所有的资源组,即在内存中创建所有资源对象,每一个资源对象对应了资源文件夹中的一个文件,但这时我们并不载入具体的资源数据,我们只在使用时才进行实际的载入操作。
loadResources();

//创建场景。在子类中重载这个函数,以创建你的场景。
createScene();
//创建帧监听器,以响应用户操作。
createFrameListener();

return true;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息