2009-12-30 37 views
5

Khi tôi sử dụng OGRE với SDL (như được mô tả trong this article), tôi có vẻ gặp sự cố với cửa sổ thứ hai xuất hiện phía sau cửa sổ hiển thị chính của tôi. Về cơ bản, mã tôi đang sử dụng là:Làm thế nào để sử dụng SDL với 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); 

Câu hỏi là, làm cách nào để thoát khỏi cửa sổ phụ?

Chỉ dành cho hậu thế, tôi đang sử dụng OGRE 1.6.4, Mac OS X 10.6.2 và SDL 1.2.14.

Trả lời

7

Tôi đã tự mình tìm ra điều này. Vấn đề kết thúc lên là phụ trợ Mac GL của OGRE không tôn trọng tùy chọn currentGLContext, vì vậy giải pháp tốt nhất là thay đổi thành SDL 1.3 (trực tiếp từ Subversion, tại thời điểm viết) và sử dụng cuộc gọi SDL_CreateWindowFrom để bắt đầu nhận sự kiện từ cửa sổ tạo bởi OGRE. Cũng cần lưu ý rằng cửa sổ OGRE cần có macAPI được đặt thành cocoa, nếu không SDL sẽ không nhận ra cửa sổ xử lý.

2

Tôi thấy rằng bạn đã giải quyết được sự cố của mình, nhưng không phải tất cả người dùng đều có nội dung bị hạ cấp SDL xuống 1,3. Bạn có thể sử dụng SDL2 và một cửa sổ SDL2 được tạo thông qua SDL_CreateWindow với OGRE. Mã sẽ trông giống như sau:

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 
Các vấn đề liên quan