How to use SDL with OGRE?

后端 未结 2 1808
鱼传尺愫
鱼传尺愫 2021-01-18 18:45

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 co

2条回答
  •  无人及你
    2021-01-18 19:36

    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
    

提交回复
热议问题