如何在OGRE中使用SDL?

5

当我按照这篇文章所述,使用SDLOGRE结合时,出现了一个在我的主渲染窗口后面的第二个窗口问题。实际上,我使用的代码如下:

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。
2个回答

7

我最终自己解决了这个问题。问题在于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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接