Ogre::String createOgreWindowIdForQWidget(QWidget* pWidget) { Q_ASSERT(pWidget != NULL); Ogre::String winId; #if defined(Q_WS_WIN) || defined(Q_WS_MAC) // positive integer for W32 (HWND handle) - According to Ogre Docs winId = Ogre::StringConverter::toString((unsigned long)(pWidget->winId())); #endif #if defined(Q_WS_X11) // poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*) for GLX - According to Ogre Docs QX11Info info = pWidget->x11Info(); winId = Ogre::StringConverter::toString((unsigned long) (info.display())); winId += ":"; winId += Ogre::StringConverter::toString((unsigned int) (info.screen())); winId += ":"; winId += Ogre::StringConverter::toString((unsigned long) (pWidget->winId())); // winId += ":"; // winId += Ogre::StringConverter::toString((unsigned long)(info.visual())); Display* display = QX11Info::display(); Q_ASSERT(display); XSync(display, False); #endif return winId; }
Ogre::NameValuePairList OgreWidget::getWinParams() { Ogre::NameValuePairList params; #if defined(Q_OS_MAC) || defined(Q_OS_WIN) params["externalWindowHandle"] = Ogre::StringConverter::toString((size_t)(this->winId())); #else #if QT_VERSION < 0x050000 const QX11Info info = this->x11Info(); Ogre::String winHandle; winHandle = Ogre::StringConverter::toString((unsigned long)(info.display())); winHandle += ":"; winHandle += Ogre::StringConverter::toString((unsigned int)(info.screen())); winHandle += ":"; winHandle += Ogre::StringConverter::toString((unsigned long)(this->winId())); winHandle += ":"; winHandle += Ogre::StringConverter::toString((unsigned long)(info.visual())); params["externalWindowHandle"] = winHandle; #elif QT_VERSION >= 0x050100 && defined(Q_WS_X11) const QX11Info info = this->x11Info(); Ogre::String winHandle; winHandle = Ogre::StringConverter::toString((unsigned long)(info.display())); winHandle += ":"; winHandle += Ogre::StringConverter::toString((unsigned int)(info.appScreen())); winHandle += ":"; winHandle += Ogre::StringConverter::toString((unsigned long)(this->winId())); params["externalWindowHandle"] = winHandle; #else // only for the time between Qt 5.0 and Qt 5.1 when QX11Info was not included params["externalWindowHandle"] = Ogre::StringConverter::toString((unsigned long)(this->winId())); #endif #endif #if defined(Q_OS_MAC) params["macAPI"] = "cocoa"; params["macAPICocoaUseNSView"] = "true"; #endif return params; }
void CarioQImageMainWindow::on_create_image_by_xlib_button_clicked() { int height = ui->label->height(); int width = ui->label->width(); QPixmap *pixmap = new QPixmap(width, height); QPainter painter(pixmap); QPaintDevice *pd = painter.device(); if(pd->devType() == QInternal::Pixmap) { QPixmap *pixmap_inner = (QPixmap*) pd; Drawable d = (Drawable) pixmap_inner->handle(); QX11Info xinfo = pixmap_inner->x11Info(); int width = pixmap_inner->width(); int height = pixmap_inner->height(); cairo_surface_t * pCairoSurface = cairo_xlib_surface_create_with_xrender_format (xinfo.display(), d, ScreenOfDisplay(xinfo.display(), xinfo.screen()), XRenderFindVisualFormat (xinfo.display(), (Visual*) xinfo.visual()), width, height); cairo_t* pCairoContext = cairo_create(pCairoSurface); cairo_surface_destroy(pCairoSurface); if(pCairoContext) { cairo_set_source_rgb (pCairoContext, 0.627, 0, 0); cairo_set_font_size (pCairoContext, 24.0); cairo_move_to (pCairoContext, 10.0, 34.0); cairo_show_text (pCairoContext, "Hello, world\nUsing Image X11 Surface"); cairo_destroy(pCairoContext); } } ui->label->setPixmap(*pixmap); }
void OgreWidget::initialise(const Ogre::NameValuePairList *miscParams) { //These attributes are the same as those use in a QGLWidget setAttribute(Qt::WA_PaintOnScreen); setAttribute(Qt::WA_NoSystemBackground); //Parameters to pass to Ogre::Root::createRenderWindow() Ogre::NameValuePairList params; //If the user passed in any parameters then be sure to copy them into our own parameter set. //NOTE: Many of the parameters the user can supply (left, top, border, etc) will be ignored //as they are overridden by Qt. Some are still useful (such as FSAA). if(miscParams != 0) { params.insert(miscParams->begin(), miscParams->end()); } //The external windows handle parameters are platform-specific Ogre::String externalWindowHandleParams; //Accept input focus setFocusPolicy(Qt::StrongFocus); #if defined(Q_WS_WIN) //positive integer for W32 (HWND handle) - According to Ogre Docs externalWindowHandleParams = Ogre::StringConverter::toString((unsigned int)(winId())); #endif #if defined(Q_WS_X11) //poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*) for GLX - According to Ogre Docs QX11Info info = x11Info(); externalWindowHandleParams = Ogre::StringConverter::toString((unsigned long)(info.display())); externalWindowHandleParams += ":"; externalWindowHandleParams += Ogre::StringConverter::toString((unsigned int)(info.screen())); externalWindowHandleParams += ":"; externalWindowHandleParams += Ogre::StringConverter::toString((unsigned long)(winId())); //externalWindowHandleParams += ":"; //externalWindowHandleParams += Ogre::StringConverter::toString((unsigned long)(info.visual())); #endif //Add the external window handle parameters to the existing params set. #if defined(Q_WS_WIN) params["externalWindowHandle"] = externalWindowHandleParams; #endif #if defined(Q_WS_X11) params["parentWindowHandle"] = externalWindowHandleParams; #endif //Finally create our window. m_pOgreRenderWindow = Ogre::Root::getSingletonPtr()->createRenderWindow("OgreWindow", width(), height(), false, ¶ms); mIsInitialised = true; }
/** * @brief setup the rendering context * @author Kito Berg-Taylor */ void OgreWidget::initializeGL() { //== Creating and Acquiring Ogre Window ==// // Get the parameters of the window QT created Ogre::String winHandle; #ifdef WIN32 // Windows code winHandle += Ogre::StringConverter::toString((unsigned long)(this->parentWidget()->winId())); #else // Unix code QX11Info info = x11Info(); winHandle = Ogre::StringConverter::toString((unsigned long)(info.display())); winHandle += ":"; winHandle += Ogre::StringConverter::toString((unsigned int)(info.screen())); winHandle += ":"; winHandle += Ogre::StringConverter::toString((unsigned long)(this->parentWidget()->winId())); #endif Ogre::NameValuePairList params; params["parentWindowHandle"] = winHandle; mOgreWindow = mOgreRoot->createRenderWindow( "QOgreWidget_RenderWindow", this->width(), this->height(), false, ¶ms ); mOgreWindow->setActive(true); WId ogreWinId = 0x0; mOgreWindow->getCustomAttribute( "WINDOW", &ogreWinId ); assert( ogreWinId ); this->create( ogreWinId ); setAttribute( Qt::WA_PaintOnScreen, true ); setAttribute( Qt::WA_NoBackground ); //== Ogre Initialization ==// Ogre::SceneType scene_manager_type = Ogre::ST_EXTERIOR_CLOSE; mSceneMgr = mOgreRoot->createSceneManager( scene_manager_type ); mSceneMgr->setAmbientLight( Ogre::ColourValue(1,1,1) ); mCamera = mSceneMgr->createCamera( "QOgreWidget_Cam" ); mCamera->setPosition( Ogre::Vector3(0,1,0) ); mCamera->lookAt( Ogre::Vector3(0,0,0) ); mCamera->setNearClipDistance( 1.0 ); Ogre::Viewport *mViewport = mOgreWindow->addViewport( mCamera ); mViewport->setBackgroundColour( Ogre::ColourValue( 0.8,0.8,1 ) ); }
void OgreWidget::initOgreSystem() { m_ogreRoot = new Ogre::Root(); Ogre::RenderSystem * renderSystem = m_ogreRoot->getRenderSystemByName("OpenGL Rendering Subsystem"); m_ogreRoot->setRenderSystem(renderSystem); m_ogreRoot->initialise(false); m_sceneManager = m_ogreRoot->createSceneManager(Ogre::ST_GENERIC); Ogre::NameValuePairList viewConfig; Ogre::String widgetHandle; #ifdef Q_WS_WIN widgetHandle = Ogre::StringConverter::toString((size_t)winId()); viewConfig["externalWindowHandle"] = widgetHandle; #else QX11Info xInfo = x11Info(); widgetHandle = Ogre::StringConverter::toString(reinterpret_cast<unsigned long>(xInfo.display())) + ":" + Ogre::StringConverter::toString(static_cast<unsigned int>(xInfo.screen())) + ":" + Ogre::StringConverter::toString(static_cast<unsigned long>(parentWidget()->winId())); viewConfig["parentWindowHandle"] = widgetHandle; #endif m_renderWindow = m_ogreRoot->createRenderWindow("Ogre rendering window", width(), height(), false, &viewConfig); #ifndef Q_WS_WIN WId window_id; m_renderWindow->getCustomAttribute("WINDOW", &window_id); create(window_id); #endif m_camera = new Camera(m_sceneManager->createCamera("myCamera")); m_camera->reset(); m_camera->getCamera()->setAspectRatio(Ogre::Real(width()) / Ogre::Real(height())); m_camera->getCamera()->setNearClipDistance(Ogre::Real(0.1)); m_viewport = m_renderWindow->addViewport(m_camera->getCamera()); m_viewport->setBackgroundColour(Ogre::ColourValue(0.5, 0.5, 0.5)); m_selectionBuffer = new SelectionBuffer(m_sceneManager, m_renderWindow); initResources(); initScene(); }
Diversia::Util::String OgreWidget::getWidgetHandle() { #if DIVERSIA_PLATFORM == DIVERSIA_PLATFORM_WIN32 return Ogre::StringConverter::toString( (size_t)( (HWND)winId() ) ); #elif DIVERSIA_PLATFORM == DIVERSIA_PLATFORM_LINUX QWidget* q_parent = dynamic_cast <QWidget *> ( parent() ); QX11Info xInfo = x11Info(); return Ogre::StringConverter::toString( (unsigned long)xInfo.display() ) + ":" + Ogre::StringConverter::toString( (unsigned int)xInfo.screen() ) + ":" + Ogre::StringConverter::toString( (unsigned long)q_parent->winId() ); #else DivAssert( 0, "Cannot get widget handle, unsupported OS" ); #endif return ""; }
void OgreWidget::initOgreSystem() { ogreRoot = new Ogre::Root(); Ogre::RenderSystem *renderSystem = ogreRoot->getRenderSystemByName("OpenGL Rendering Subsystem"); ogreRoot->setRenderSystem(renderSystem); ogreRoot->initialise(false); ogreSceneManager = ogreRoot->createSceneManager(Ogre::ST_GENERIC); Ogre::NameValuePairList viewConfig; Ogre::String widgetHandle; #ifdef Q_WS_WIN widgetHandle = Ogre::StringConverter::toString((size_t)((HWND)winId())); #else QWidget *q_parent = dynamic_cast <QWidget *> (parent()); QX11Info xInfo = x11Info(); widgetHandle = Ogre::StringConverter::toString ((unsigned long)xInfo.display()) + ":" + Ogre::StringConverter::toString ((unsigned int)xInfo.screen()) + ":" + Ogre::StringConverter::toString ((unsigned long)q_parent->winId()); #endif viewConfig["externalWindowHandle"] = widgetHandle; ogreRenderWindow = ogreRoot->createRenderWindow("Ogre rendering window", width(), height(), false, &viewConfig); ogreCamera = ogreSceneManager->createCamera("myCamera"); Ogre::Vector3 camPos(0, 50,150); ogreCamera->setPosition(camPos); ogreCamera->lookAt(0,50,0); emit cameraPositionChanged(camPos); ogreViewport = ogreRenderWindow->addViewport(ogreCamera); ogreViewport->setBackgroundColour(Ogre::ColourValue(0,0,255)); ogreCamera->setAspectRatio(Ogre::Real(width()) / Ogre::Real(height())); setupNLoadResources(); createScene(); }
/** * @brief setup the rendering context * @author Kito Berg-Taylor */ void OgreWidget::initializeGL() { //== Creating and Acquiring Ogre Window ==// // Get the parameters of the window QT created Ogre::String winHandle; #ifdef WIN32 // Windows code winHandle += Ogre::StringConverter::toString((unsigned long)(this->parentWidget()->winId())); #elif MACOS // Mac code, tested on Mac OSX 10.6 using Qt 4.7.4 and Ogre 1.7.3 Ogre::String winHandle = Ogre::StringConverter::toString(winId()); #else // Unix code QX11Info info = x11Info(); winHandle = Ogre::StringConverter::toString((unsigned long)(info.display())); winHandle += ":"; winHandle += Ogre::StringConverter::toString((unsigned int)(info.screen())); winHandle += ":"; winHandle += Ogre::StringConverter::toString((unsigned long)(this->parentWidget()->winId())); #endif Ogre::NameValuePairList params; #ifndef MACOS // code for Windows and Linux params["parentWindowHandle"] = winHandle; _mOgreWindow = _mOgreRoot->createRenderWindow( "QOgreWidget_RenderWindow", this->width(), this->height(), false, ¶ms); _mOgreWindow->setActive(true); WId ogreWinId = 0x0; _mOgreWindow->getCustomAttribute("WINDOW", &ogreWinId); assert(ogreWinId); // bug fix, extract geometry QRect geo = this->frameGeometry(); // create new window this->create(ogreWinId); // set geometrie infos to new window this->setGeometry(geo); #else // code for Mac params["externalWindowHandle"] = winHandle; params["macAPI"] = "cocoa"; params["macAPICocoaUseNSView"] = "true"; mOgreWindow = mOgreRoot->createRenderWindow("QOgreWidget_RenderWindow", width(), height(), false, ¶ms); mOgreWindow->setActive(true); makeCurrent(); #endif setAttribute(Qt::WA_PaintOnScreen, true); setAttribute(Qt::WA_NoBackground); //== Ogre Initialization ==// Ogre::SceneType scene_manager_type = Ogre::ST_EXTERIOR_CLOSE; _mSceneMgr = _mOgreRoot->createSceneManager(scene_manager_type); _mSceneMgr->setAmbientLight(Ogre::ColourValue(1.0f, 1.0f, 1.0f)); _mCamera = _mSceneMgr->createCamera("QOgreWidget_Cam"); _mCamera->setPosition(Ogre::Vector3(0, 0, 80)); _mCamera->lookAt(Ogre::Vector3(0, 0, -300)); _mCamera->setNearClipDistance(1.0f); Ogre::Viewport *mViewport = _mOgreWindow->addViewport(_mCamera); mViewport->setBackgroundColour(Ogre::ColourValue(0.1f, 0.1f, 1.0f)); /* Ogre::ConfigFile cf; cf.load("resources.cfg"); // Go through all sections & settings in the file Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); Ogre::String secName, typeName, archName; while (seci.hasMoreElements()) { secName = seci.peekNextKey(); Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); Ogre::ConfigFile::SettingsMultiMap::iterator i; for (i = settings->begin(); i != settings->end(); ++i) { typeName = i->first; archName = i->second; Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); } } // load resources Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); //------------------------------------------------------------------------------------- // Create the scene Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh"); Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); headNode->attachObject(ogreHead); // Set ambient light mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5)); // Create a light Ogre::Light* l = mSceneMgr->createLight("MainLight"); l->setPosition(20,80,50); */ }
void OgreWidget::create_render_window () { if (win_) return; bool stealparent (parentWidget() != NULL); QWidget *nativewin ((stealparent)? parentWidget () : this); Ogre::NameValuePairList params; Ogre::String winhandle; #ifdef Q_WS_WIN // According to Ogre Docs // positive integer for W32 (HWND handle) winhandle = Ogre::StringConverter::toString ((unsigned int) (nativewin-> winId ())); //Add the external window handle parameters to the existing params set. params["externalWindowHandle"] = winhandle; #endif #ifdef Q_WS_X11 // GLX - According to Ogre Docs: // poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*) QX11Info info = x11Info (); winhandle = Ogre::StringConverter::toString ((unsigned long) (info.display ())); winhandle += ":"; winhandle += Ogre::StringConverter::toString ((unsigned int) (info.screen ())); winhandle += ":"; winhandle += Ogre::StringConverter::toString ((unsigned long) nativewin-> winId()); //(isHidden ()) ? //nativewin-> effectiveWinId () : //nativewin-> winId ()); //Add the external window handle parameters to the existing params set. params["parentWindowHandle"] = winhandle; #endif win_ = root_-> createRenderWindow ("View", width(), height(), false, ¶ms); // take over ogre window // needed with parent windows if (stealparent) { WId ogre_winid = 0x0; #ifndef Q_WS_WIN win_-> getCustomAttribute ("WINDOW", &ogre_winid); #else win_-> getCustomAttribute ("HWND", &ogre_winid); #endif assert (ogre_winid); create (ogre_winid); } }
void RenderWindow::CreateRenderWindow(QWidget *targetWindow, const QString &name, int width, int height, int left, int top, bool fullscreen, Framework *fw) { Ogre::NameValuePairList params; #ifdef ANDROID fullscreen = true; /// \todo This should not be done here, but doing it in Tundra's main seems to be unreliable and lead to crashes JavaVM* vm = Framework::JavaVMInstance(); JNIEnv* env; vm->AttachCurrentThread(&env, 0); if (vm->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK) { LogError("CreateRenderWindow: GetEnv failed"); return; } Framework::SetJniEnvInstance(env); if (!env) { LogError("CreateRenderWindow: Null Java environment, can not call Java methods"); return; } jobject result = env->CallStaticObjectMethod(qtApplicationClass, getSurfaceMethod); if (!result) { LogError("CreateRenderWindow: Surface was null"); return; } /* jclass clsID = env->GetObjectClass(result); jmethodID msgMethodID; const char* localstr = NULL; jclass javaClassClsID = env->FindClass("java/lang/Class"); msgMethodID = env->GetMethodID(javaClassClsID, "getName", "()Ljava/lang/String;"); if(msgMethodID == NULL) LogInfo("Null getName method"); else { jstring clsName = (jstring)env->CallObjectMethod(clsID, msgMethodID); localstr = env->GetStringUTFChars(clsName, NULL); LogInfo("Surface class name: " + QString(localstr)); } */ LogInfo("CreateRenderWindow: calling ANativeWindow_fromSurface"); ANativeWindow* window = ANativeWindow_fromSurface(env, result); params["externalWindowHandle"] = Ogre::StringConverter::toString((int)window); #endif /** See http://www.ogre3d.org/tikiwiki/RenderWindowParameters @note All the values must be strings. Assigning int/bool etc. directly to the map produces a empty string value! @bug Check if the keys and values are valid from Ogre::RenderSystem::getConfigOptions(). If you feed carbage to the map outside the accepted values (eg. FSAA) you may crash when the render window is created. Additionally if the map keys are case sensitive we might have bugs below (eg. vsync vs. VSync)! */ if (fw->CommandLineParameters("--vsyncFrequency").length() > 0) // "Display frequency rate; only applies if fullScreen is set." params["displayFrequency"] = fw->CommandLineParameters("--vsyncFrequency").first().toStdString(); if (fw->CommandLineParameters("--vsync").length() > 0) // "Synchronize buffer swaps to monitor vsync, eliminating tearing at the expense of a fixed frame rate" params["vsync"] = fw->CommandLineParameters("--vsync").first().toStdString(); else if (fw->Config()->HasKey(ConfigAPI::FILE_FRAMEWORK, ConfigAPI::SECTION_RENDERING, "vsync")) { QString value = fw->Config()->Get(ConfigAPI::FILE_FRAMEWORK, ConfigAPI::SECTION_RENDERING, "vsync", "").toString(); if (!value.isEmpty()) params["vsync"] = value.toStdString(); } if (fw->CommandLineParameters("--antialias").length() > 0) // "Full screen antialiasing factor" params["FSAA"] = fw->CommandLineParameters("--antialias").first().toStdString(); else if (fw->Config()->HasKey(ConfigAPI::FILE_FRAMEWORK, ConfigAPI::SECTION_RENDERING, "antialias")) { // Accepted FSAA values can be more than just a number, allow any string from config file. QString value = fw->Config()->Get(ConfigAPI::FILE_FRAMEWORK, ConfigAPI::SECTION_RENDERING, "antialias", "").toString(); if (!value.isEmpty()) params["FSAA"] = value.toStdString(); } #ifdef WIN32 if (targetWindow) params["externalWindowHandle"] = Ogre::StringConverter::toString((unsigned int)targetWindow->winId()); #endif #ifdef Q_WS_MAC Ogre::String winhandle; QWidget* nativewin = targetWindow; while(nativewin && nativewin->parentWidget()) nativewin = nativewin->parentWidget(); // according to // http://www.ogre3d.org/forums/viewtopic.php?f=2&t=27027 does winhandle = Ogre::StringConverter::toString( (unsigned long)nativewin ? nativewin->winId() : 0); //Add the external window handle parameters to the existing params set. params["externalWindowHandle"] = winhandle; /* According to http://doc.qt.nokia.com/stable/qwidget.html#winId "On Mac OS X, the type returned depends on which framework Qt was linked against. -If Qt is using Carbon, the {WId} is actually an HIViewRef. -If Qt is using Cocoa, {WId} is a pointer to an NSView." Ogre needs to know that a NSView handle will be passed to its' externalWindowHandle parameter, otherwise it assumes that NSWindow will be used */ params["macAPI"] = "cocoa"; params["macAPICocoaUseNSView"] = "true"; #endif #ifdef Q_WS_X11 QWidget *parent = targetWindow; while(parent && parent->parentWidget()) parent = parent->parentWidget(); // GLX - According to Ogre Docs: // poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*) QX11Info info = targetWindow->x11Info(); Ogre::String winhandle = Ogre::StringConverter::toString((unsigned long)(info.display())); winhandle += ":" + Ogre::StringConverter::toString((unsigned int)(info.screen())); winhandle += ":" + Ogre::StringConverter::toString((unsigned long)parent ? parent->winId() : 0); //Add the external window handle parameters to the existing params set. params["parentWindowHandle"] = winhandle; #endif // Window position to params if (left != -1) params["left"] = Ogre::StringConverter::toString(left); if (top != -1) params["top"] = Ogre::StringConverter::toString(top); #ifdef WIN32 if (fw->HasCommandLineParameter("--perfHud")) { params["useNVPerfHUD"] = "true"; params["Rendering Device"] = "NVIDIA PerfHUD"; } #endif renderWindow = Ogre::Root::getSingletonPtr()->createRenderWindow(name.toStdString().c_str(), width, height, fullscreen, ¶ms); renderWindow->setDeactivateOnFocusChange(false); // Currently do not create UI overlay on Android to save fillrate #ifndef ANDROID CreateRenderTargetOverlay(width, height); #endif }
Ogre::RenderWindow *QOgreUIView::CreateRenderWindow () { bool stealparent ((parentWidget())? true : false); QWidget *nativewin ((stealparent)? parentWidget() : this); Ogre::NameValuePairList params; Ogre::String winhandle; #ifdef Q_WS_WIN // According to Ogre Docs // positive integer for W32 (HWND handle) winhandle = Ogre::StringConverter::toString ((unsigned int) (nativewin-> winId ())); //Add the external window handle parameters to the existing params set. params["externalWindowHandle"] = winhandle; #endif #ifdef Q_WS_X11 // GLX - According to Ogre Docs: // poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*) QX11Info info = x11Info (); winhandle = Ogre::StringConverter::toString ((unsigned long) (info.display ())); winhandle += ":"; winhandle += Ogre::StringConverter::toString ((unsigned int) (info.screen ())); winhandle += ":"; winhandle += Ogre::StringConverter::toString ((unsigned long) nativewin-> winId()); //Add the external window handle parameters to the existing params set. params["parentWindowHandle"] = winhandle; #endif QSize size (nativewin-> size()); win_ = Ogre::Root::getSingletonPtr()-> createRenderWindow ("View", size.width(), size.height(), false, ¶ms); // take over ogre window // needed with parent windows if (stealparent) { WId ogre_winid = 0x0; #ifndef Q_WS_WIN win_-> getCustomAttribute ("WINDOW", &ogre_winid); #else win_-> getCustomAttribute ("HWND", &ogre_winid); #endif assert (ogre_winid); create (ogre_winid); } return win_; }
void RenderWindow::CreateRenderWindow(QWidget *targetWindow, const QString &name, int width, int height, int left, int top, bool fullscreen) { Ogre::NameValuePairList params; #ifdef WIN32 params["externalWindowHandle"] = Ogre::StringConverter::toString((unsigned int)targetWindow->winId()); #endif #ifdef Q_WS_MAC // qt docs say it's a HIViewRef on carbon, // carbon docs say HIViewGetWindow gets a WindowRef out of it Ogre::String winhandle; QWidget* nativewin = targetWindow; while(nativewin->parentWidget()) nativewin = nativewin->parentWidget(); #if 0 HIViewRef vref = (HIViewRef) nativewin-> winId (); WindowRef wref = HIViewGetWindow(vref); winhandle = Ogre::StringConverter::toString( (unsigned long) (HIViewGetRoot(wref))); #else // according to // http://www.ogre3d.org/forums/viewtopic.php?f=2&t=27027 does winhandle = Ogre::StringConverter::toString( (unsigned long) nativewin->winId()); #endif //Add the external window handle parameters to the existing params set. params["externalWindowHandle"] = winhandle; #endif #ifdef Q_WS_X11 QWidget *parent = targetWindow; while(parent->parentWidget()) parent = parent->parentWidget(); // GLX - According to Ogre Docs: // poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*) QX11Info info = targetWindow->x11Info(); Ogre::String winhandle = Ogre::StringConverter::toString((unsigned long)(info.display())); winhandle += ":" + Ogre::StringConverter::toString((unsigned int)(info.screen())); winhandle += ":" + Ogre::StringConverter::toString((unsigned long)parent->winId()); //Add the external window handle parameters to the existing params set. params["parentWindowHandle"] = winhandle; #endif // Window position to params if (left != -1) params["left"] = ToString(left); if (top != -1) params["top"] = ToString(top); #ifdef USE_NVIDIA_PERFHUD params["useNVPerfHUD"] = "true"; params["Rendering Device"] = "NVIDIA PerfHUD"; #endif renderWindow = Ogre::Root::getSingletonPtr()->createRenderWindow(name.toStdString().c_str(), width, height, fullscreen, ¶ms); renderWindow->setDeactivateOnFocusChange(false); CreateRenderTargetOverlay(width, height); }
/** *@brief Ogre3Dのレンダリングの表示のウィジェットのコンストラクタ * @param parent 親ウィジェット */ OgreWidget::OgreWidget(QWidget *parent) : #ifdef Q_OS_WIN QWidget(parent,Qt::WindowFlags(Qt::MSWindowsOwnDC)) #else QWidget(parent) #endif { QTextCodec* tc = QTextCodec::codecForLocale(); setAttribute(Qt::WA_PaintOnScreen); setAutoFillBackground(true); setAttribute(Qt::WA_NoBackground); setAttribute(Qt::WA_InputMethodEnabled); setMouseTracking(true); setFocusPolicy(Qt::WheelFocus); //setAcceptDrops(true); setContextMenuPolicy( Qt::PreventContextMenu ); setMaximumSize(windowSizeX, windowSizeY); setMinimumSize(windowSizeX, windowSizeY); //setSizeIncrement(1024, 768); //update(); } /** *@brief Ogre3Dのレンダリングの表示のウィジェットのデストラクタ */ OgreWidget::~OgreWidget(void) { } /** *@brief レンダリング初期化 */ void OgreWidget::initOgre() { { Ogre::String winHandle; #ifdef Q_OS_WIN winHandle = Ogre::StringConverter::toString((size_t)((HWND)winId())); //winHandle += Ogre::StringConverter::toString((unsigned long)(winId())); #else QX11Info info = this->x11Info(); winHandle = Ogre::StringConverter::toString((unsigned long)(info.display())); winHandle += ":"; winHandle += Ogre::StringConverter::toString((unsigned int)(info.screen())); winHandle += ":"; winHandle += Ogre::StringConverter::toString((unsigned long)(window()->winId())); #endif mOgreRTCApplication = OgreRTCApplication::getSingletonPtr(); WId ogreWinId = mOgreRTCApplication->initRenderWindow(winHandle, windowSizeX, windowSizeY); #ifdef Q_OS_WIN #else QRect geo = this->frameGeometry(); create(ogreWinId); setGeometry(geo); #endif //mOgreApp->start(); mOgreRTCApplication->update(100); }
void OgreWidget::init() { //These attributes are the same as those use in a QGLWidget setAttribute(Qt::WA_PaintOnScreen); setAttribute(Qt::WA_NoSystemBackground); //Parameters to pass to Ogre::Root::createRenderWindow() Ogre::NameValuePairList params; params["useNVPerfHUD"] = "true"; //The external windows handle parameters are platform-specific Ogre::String externalWindowHandleParams; //Accept input focus setFocusPolicy(Qt::StrongFocus); #if defined(Q_WS_WIN) || defined(Q_WS_MAC) //positive integer for W32 (HWND handle) - According to Ogre Docs externalWindowHandleParams = Ogre::StringConverter::toString((size_t)(winId())); #endif #if defined(Q_WS_X11) //poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*) for GLX - According to Ogre Docs QX11Info info = x11Info(); externalWindowHandleParams = Ogre::StringConverter::toString((unsigned long)(info.display())); externalWindowHandleParams += ":"; externalWindowHandleParams += Ogre::StringConverter::toString((unsigned int)(info.screen())); externalWindowHandleParams += ":"; externalWindowHandleParams += Ogre::StringConverter::toString((unsigned long)(this->parentWidget()->winId())); // winHandle += Ogre::StringConverter::toString((unsigned long)(this->window()->winId())); //params["parentWindowHandle"] = winHandle; #endif //Add the external window handle parameters to the existing params set. #if defined(Q_WS_WIN) || defined(Q_WS_MAC) params["externalWindowHandle"] = externalWindowHandleParams; #endif #if defined(Q_WS_X11) params["parentWindowHandle"] = externalWindowHandleParams; #endif #if defined(Q_WS_MAC) params["macAPI"] = "cocoa"; params["macAPICocoaUseNSView"] = "true"; #endif //Finally create our window. mOgreWindow = this->mOgreRoot->createRenderWindow( "OgreWindow" + QString::number(ogrewidgetCpt++).toStdString() , 640, 480, false, ¶ms); mOgreWindow->setActive(true); WId ogreWinId = 0x0; mOgreWindow->getCustomAttribute( "WINDOW", &ogreWinId ); //assert( ogreWinId ); #if defined(Q_WS_X11) // TAG: Build on linux create( ogreWinId ); #endif // Create the free camera (FIXME no encapsulation) if(mCamera == NULL){ Ogre::Camera* cam1 = mSceneMgr->createCamera("firstCamera"); cam1->setPosition(Ogre::Vector3(0, 2, 6)); cam1->lookAt(Ogre::Vector3(0, 2, 0)); cam1->setNearClipDistance(0.01); // 10 mm cam1->setFarClipDistance(5000); // 1km mCamera = cam1; } mViewport = mOgreWindow->addViewport( mCamera ); mViewport->setBackgroundColour( Ogre::ColourValue( 0.5,0.5,1 ) ); mViewport->setOverlaysEnabled(true); mIsInit = true; resized = true; ogreFreeCamera = new OgreFreeCamera(mCamera); connect(this,SIGNAL(keyPressed(QKeyEvent*)),ogreFreeCamera,SLOT(keyPressEvent(QKeyEvent*))); connect(this,SIGNAL(keyReleased(QKeyEvent*)),ogreFreeCamera,SLOT(keyReleaseEvent(QKeyEvent*))); connect(this,SIGNAL(mouseMoved(QMouseEvent*)),ogreFreeCamera,SLOT(mouseMoveEvent(QMouseEvent*))); connect(this,SIGNAL(mousePressed(QMouseEvent*)),ogreFreeCamera,SLOT(mousePressEvent(QMouseEvent*))); connect(this,SIGNAL(mouseReleased(QMouseEvent*)),ogreFreeCamera,SLOT(mouseReleaseEvent(QMouseEvent*))); connect(this,SIGNAL(entered(QEvent*)),ogreFreeCamera,SLOT(enterViewPortEvent(QEvent*))); connect(this,SIGNAL(leaved(QEvent*)),ogreFreeCamera,SLOT(leaveViewPortEvent(QEvent*))); connect(this,SIGNAL(stepped()),ogreFreeCamera,SLOT(step())); }
Ogre::RenderWindow* ExternalRenderWindow::CreateRenderWindow(const std::string &name, int width, int height, int left, int top, bool fullscreen) { bool stealparent ((parentWidget())? true : false); QWidget *nativewin ((stealparent)? parentWidget() : this); Ogre::NameValuePairList params; Ogre::String winhandle; #ifdef Q_WS_WIN // According to Ogre Docs // positive integer for W32 (HWND handle) winhandle = Ogre::StringConverter::toString ((unsigned int) (nativewin-> winId ())); //Add the external window handle parameters to the existing params set. params["externalWindowHandle"] = winhandle; #endif #ifdef Q_WS_MAC // qt docs say it's a HIViewRef on carbon, // carbon docs say HIViewGetWindow gets a WindowRef out of it #if 0 HIViewRef vref = (HIViewRef) nativewin-> winId (); WindowRef wref = HIViewGetWindow(vref); winhandle = Ogre::StringConverter::toString( (unsigned long) (HIViewGetRoot(wref))); #else // according to // http://www.ogre3d.org/forums/viewtopic.php?f=2&t=27027 does winhandle = Ogre::StringConverter::toString( (unsigned long) nativewin->winId()); #endif //Add the external window handle parameters to the existing params set. params["externalWindowHandle"] = winhandle; #endif #ifdef Q_WS_X11 // GLX - According to Ogre Docs: // poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*) QX11Info info = x11Info (); winhandle = Ogre::StringConverter::toString ((unsigned long) (info.display ())); winhandle += ":"; winhandle += Ogre::StringConverter::toString ((unsigned int) (info.screen ())); winhandle += ":"; winhandle += Ogre::StringConverter::toString ((unsigned long) nativewin-> winId()); //Add the external window handle parameters to the existing params set. params["parentWindowHandle"] = winhandle; #endif // Window position to params if (left != -1) params["left"] = ToString(left); if (top != -1) params["top"] = ToString(top); render_window_ = Ogre::Root::getSingletonPtr()-> createRenderWindow(name, width, height, fullscreen, ¶ms); return render_window_; }