2009-12-30 20 views
5

Quando utilizzo OGRE con SDL (come descritto in this article), sembra che si stia riscontrando un problema con una seconda finestra visualizzata dietro la finestra di rendering principale. Fondamentalmente, il codice che sto usando è questo:Come utilizzare SDL con OGRE?

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

La domanda è: come faccio a eliminare la finestra aggiuntiva?

Solo per i posteri, sto usando OGRE 1.6.4, Mac OS X 10.6.2 e SDL 1.2.14.

risposta

7

Ho finito per capirlo da solo. Il problema è che il backend Mac GL di OGRE non onora l'opzione currentGLContext, quindi la soluzione migliore è passare a SDL 1.3 (direttamente da Subversion, al momento della scrittura) e utilizzare la chiamata SDL_CreateWindowFrom per iniziare a ricevere eventi da una finestra creato da OGRE. Va anche notato che la finestra OGRE deve avere il macAPI impostato su cocoa, altrimenti SDL non riconoscerà l'handle della finestra.

2

Vedo che hai già risolto il problema, ma non tutti gli utenti si accontentano di eseguire il downgrade di SDL a 1.3. È possibile utilizzare SDL2 e una finestra SDL2 creata tramite SDL_CreateWindow con OGRE. Il codice sarebbe simile a questo:

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 
Problemi correlati