如何将 SDL 与 OGRE 结合使用?

发布于 2024-08-16 05:08:43 字数 848 浏览 10 评论 0原文

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

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。

When I go to use OGRE with SDL (as described in this article), I seem to be having trouble with a second window that appears behind my main render window. Basically, the code I'm using is this:

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);

The question is, how do I get rid of the extra window?

Just for posterity, I'm using OGRE 1.6.4, Mac OS X 10.6.2, and SDL 1.2.14.

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

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

发布评论

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

评论(2

悲喜皆因你 2024-08-23 05:08:43

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

I ended up figuring this out on my own. The problem ends up being that OGRE's Mac GL backend does not honor the currentGLContext option, so the best solution is to change to SDL 1.3 (directly from Subversion, as of time of writing) and use the SDL_CreateWindowFrom call to start getting events from a window created by OGRE. It should also be noted that the OGRE window needs to have the macAPI set to cocoa, or else SDL won't recognize the window handle.

水晶透心 2024-08-23 05:08:43

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

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, ¶ms);
// see OGRE documentation on how to populate width, height, and isFullscreen to suit your needs

// create OGRE scene manager, camera, viewports, etc

I see that you already solved your problem, but not all users will be content with downgrading SDL to 1.3. You can use SDL2 and an SDL2 window created via SDL_CreateWindow with OGRE. The code would look something like this:

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, ¶ms);
// see OGRE documentation on how to populate width, height, and isFullscreen to suit your needs

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