如何在 Ogre 中获得无窗口应用程序?

发布于 2024-08-23 17:53:32 字数 105 浏览 5 评论 0原文

我正在尝试创建一个无窗口的 Ogre 应用程序,但应用程序似乎完全忽略了 RenderWindow::setVisible(false) 方法。有办法实现吗?

谢谢
托马索

I'm trying to create a windowless Ogre application, but it seems that the method RenderWindow::setVisible(false) is completely ignored by the application. Is there a way to accomplish that?

Thank you
Tommaso

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

止于盛夏 2024-08-30 17:53:32

您不应该使用 RenderWindow ,而是使用 RenderTexture< /code>如果您不想打开窗口。它的工作方式几乎与 RenderWindow 完全相同,因为它也是从 RenderTarget 派生的。除了更改构造函数之外,您只需使用当前参数切换它们就应该几乎没有问题。

如果您在开关方面遇到问题,请使用一些具体代码更新您的问题。

You should not be using RenderWindow but RenderTexture if you don't want to open a window. It works almost exactly the same as RenderWindow because it is derived from RenderTarget as well. You should have almost no trouble just switching them around with your current parameters except for changing the constructor.

Please update your question with some concrete code if you do run into trouble with the switch.

混吃等死 2024-08-30 17:53:32

据我所知,即使您只想创建一个无窗口应用程序,您也必须创建一个窗口。不创建 RenderWindow 就无法初始化 Ogre (window = m_root->initialise(true, "App"))
在 Ogre 1.8 中,您可以通过调用 window->setHidden(true) 来隐藏窗口
通过这种方法,您可以绕过该问题并制作一个“无窗口”应用程序。

正如 Svenstaro 所说,您可以将渲染重定向到 RenderTexture 中。我使用下面的代码将帧渲染为纹理:

m_window = m_root->initialise(true, "App");
m_window->setHidden(true);
Ogre::WindowEventUtilities::messagePump(); // Force the window to be hidden (necessary under Ubuntu for my case)

m_camera = m_sceneMgr->createCamera("Cam");

Ogre::TexturePtr rtt_texture = Ogre::TextureManager::getSingleton().createManual("RttTex",
                Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                Ogre::TEX_TYPE_2D, 640, 480, 0,
                Ogre::PF_R8G8B8,
                Ogre::TU_RENDERTARGET);

Ogre::RenderTexture* m_tex = rtt_texture->getBuffer()->getRenderTarget();
Ogre::Viewport* vp = m_tex->addViewport(m_camera);
vp->setClearEveryFrame(true);
vp->setBackgroundColour(Ogre::ColourValue::Black);
vp->setOverlaysEnabled(false);
m_camera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));

在 RenderLoop 中:

while(1)
{
  m_root->renderOneFrame();
  m_tex->update();

  // Other stuffs
}

As far as I know you have to create a window even if you just want create a windowless app. It is not possible to initialize Ogre without creating a RenderWindow (window = m_root->initialise(true, "App"))
With Ogre 1.8 you can hide the window by calling window->setHidden(true)
Thanks to this method you can bypass the problem and make a "windowless" app.

As Svenstaro said, you can redirect the rendering into a RenderTexture. I use the code below to render my frames into a texture :

m_window = m_root->initialise(true, "App");
m_window->setHidden(true);
Ogre::WindowEventUtilities::messagePump(); // Force the window to be hidden (necessary under Ubuntu for my case)

m_camera = m_sceneMgr->createCamera("Cam");

Ogre::TexturePtr rtt_texture = Ogre::TextureManager::getSingleton().createManual("RttTex",
                Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                Ogre::TEX_TYPE_2D, 640, 480, 0,
                Ogre::PF_R8G8B8,
                Ogre::TU_RENDERTARGET);

Ogre::RenderTexture* m_tex = rtt_texture->getBuffer()->getRenderTarget();
Ogre::Viewport* vp = m_tex->addViewport(m_camera);
vp->setClearEveryFrame(true);
vp->setBackgroundColour(Ogre::ColourValue::Black);
vp->setOverlaysEnabled(false);
m_camera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));

In the RenderLoop :

while(1)
{
  m_root->renderOneFrame();
  m_tex->update();

  // Other stuffs
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文