【问题标题】:How to use SDL with OGRE?如何在 OGRE 中使用 SDL?
【发布时间】:2009-12-30 07:22:01
【问题描述】:

当我将OGRESDL 一起使用(如this article 中所述)时,我似乎遇到了出现在主渲染窗口后面的第二个窗口的问题。基本上,我使用的代码是这样的:

SDL_init(SDL_INIT_VIDEO);
SDL_Surface *screen = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);

Ogre::Root *root = new Ogre::Root();
root->restoreConfig();
root->initialise(false);

Ogre::NameValuePairList windowSettings;
windowSettings["currentGLContext"] = Ogre::String("True");
Ogre::RenderWindow *window = root->createRenderWindow("MainRenderWindow", 640, 480, false, &windowSettings);
window->setVisible(true);

问题是,如何去掉多余的窗口?

为了后代,我使用的是 OGRE 1.6.4、Mac OS X 10.6.2 和 SDL 1.2.14。

【问题讨论】:

    标签: c++ sdl ogre3d


    【解决方案1】:

    我最终自己解决了这个问题。问题最终是 OGRE 的 Mac GL 后端不支持 currentGLContext 选项,因此最好的解决方案是更改为 SDL 1.3(在撰写本文时直接来自 Subversion)并使用 SDL_CreateWindowFrom 调用开始获取来自 OGRE 创建的窗口中的事件。还需要注意的是,OGRE 窗口需要将macAPI 设置为cocoa,否则 SDL 将无法识别窗口句柄。

    【讨论】:

      【解决方案2】:

      我看到您已经解决了您的问题,但并非所有用户都对将 SDL 降级到 1.3 感到满意。您可以将 SDL2 和通过 SDL_CreateWindow 创建的 SDL2 窗口与 OGRE 一起使用。代码看起来像这样:

      if (SDL_Init(SDL_INIT_VIDEO) != 0) {
          OGRE_EXCEPT(Ogre::Exception::ERR_INTERNAL_ERROR, "Cannot initialize SDL2!",
              "BaseApplication::setup");
      }
      
      Ogre::Root *root = new Ogre::Root();
      root->restoreConfig();
      root->initialise(false);
      
      Ogre::NameValuePairList params; // ogre window / render system params
      SDL_Window *sdlWindow = SDL_CreateWindow("myWindow", posX, posY, width, height, vflags);
      // see SDL_CreateWindow docs / examples for how to populate posX, posY, width, height, and vflags according to your needs
      
      SDL_SysWMinfo wmInfo;
      SDL_VERSION(&wmInfo.version);
      if (SDL_GetWindowWMInfo(sdlWindow, &wmInfo) == SDL_FALSE) {
          OGRE_EXCEPT(Ogre::Exception::ERR_INTERNAL_ERROR,
              "Couldn't get WM Info! (SDL2)",
              "BaseApplication::setup");
      }
      
      params.insert(std::make_pair("macAPI", "cocoa"));
      params.insert(std::make_pair("macAPICocoaUseNSView", "true"));
      
      // grab a string representing the NSWindow pointer
      Ogre::String winHandle = Ogre::StringConverter::toString((unsigned long)wmInfo.info.cocoa.window);
      
      // assign the NSWindow pointer to the parentWindowHandle parameter
      params.insert(std::make_pair("parentWindowHandle", winHandle));
      
      Ogre::RenderWindow *ogreWindow = root->createRenderWindow("myWindowTitle", width, height, isFullscreen, &params);
      // see OGRE documentation on how to populate width, height, and isFullscreen to suit your needs
      
      // create OGRE scene manager, camera, viewports, etc
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-07
        • 2015-06-19
        • 1970-01-01
        相关资源
        最近更新 更多