您的位置:首页 > 其它

去掉ogre引擎设置的窗口

2016-12-30 11:30 232 查看
转载自:http://blog.163.com/chenkangapple@126/blog/static/12807484720098173383407/

每次运行前总会出现讨厌的Ogre界面,那怎么去除它呢?这个需要了解当初第一节时建立一个Ogre窗口的原理。

每次用Ogre时总会包含ExampleApplication.h,在这个头文件中定义了一个ExampleApplication类,其中有个这样的方法.

virtual bool configure(void)
{
// Show the configuration dialog and initialise the system
// You can skip this and use root.restoreConfig() to load configuration
// settings if you were sure there are valid ones saved in ogre.cfg
if(mRoot->showConfigDialog())    //这是关键地方
{
// If returned true, user clicked OK so initialise
// Here we choose to let the system create a default rendering window by passing 'true'
mWindow = mRoot->initialise(true);
return true;
}
else
{
return false;
}
}


仔细看这段代码,发现有个

if(mRoot->showConfigDialog()){}


这就话的意思就是显示Ogre对话框,既然知道问题是他,那怎么修改?

在OgreRoot.h中我们可以看到有这样的方法

Root::restoreConfig(void){}


这个是干什么的? 不难发现,仔细观察这段代码,发现原来这个是“恢复设置”的,既然这样,那么回到原来的地方咱们把ExampleApplication.h中的那个方法修改一下:

virtual bool configure(void)
{
// Show the configuration dialog and initialise the system
// You can skip this and use root.restoreConfig() to load configuration
// settings if you were sure there are valid ones saved in ogre.cfg
// if(mRoot->showConfigDialog())    //原来的地方
if(mRoot->restoreConfig())          //现在修改后的地方
{
// If returned true, user clicked OK so initialise
// Here we choose to let the system create a default rendering window by passing 'true'
mWindow = mRoot->initialise(true);
return true;
}
else
{
return false;
}
}


运行自己原来写的程序,呵呵,讨厌的Ogre对话框没有了。

不过这个有个前提,你必须运行一次那个带配置窗口的示例才会有效果,为什么呢?

因为在运行那个带配置的对话框之后会生成一个ogre.cfg文件,如果没有这个文件的话,会提示有错的,因为咱们这样一改是通过这个配置文件进入到Ogre窗口的。没有铁定会报错。

如果想以后制作自己的配置窗口建议看一下restoreConfig(),saveconfig()的工作机制。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ogre