I was trying to embed an Irrlicht Window in a Qt Widget under Linux, but it didn't work first. I looked on the forum, where I found several topics, and tried to do as indicated, but nothing worked. So I decided to look at the Irrlicht code, and discovered that it was just not implemented. It seems that the provided patches have not been included in the repository. So I made some modifications, and managed to have something working. I also had to add an attribute in the SExposedVideoData.OpenGLLinux struct so that I could get the XWindow id, and resize the window when my widget is resized.
Now, an embedded window can be created this way, with a Qt Widget :
Code: Select all
irr::SIrrlichtCreationParameters params;
params.WindowId = (void*)winId();
params.DriverType = irr::video::EDT_OPENGL;
_device = irr::createDeviceEx(params);
Code: Select all
void IrrlichtContainer::resizeEvent(QResizeEvent * event)
{
if(getDevice())
{
XResizeWindow((Display*)(getDevice()->getVideoDriver()->getExposedVideoData().OpenGLLinux.X11Display),
getDevice()->getVideoDriver()->getExposedVideoData().OpenGLLinux.X11Window,
property("width").toInt(),
property("height").toInt());
getDevice()->getVideoDriver()->setViewPort(irr::core::rect<irr::s32>(0, 0, property("width").toInt(), property("height").toInt()));
}
}
Code: Select all
diff -r -x '*.o' irrlicht-1.4/include/SExposedVideoData.h irrlicht-1.4_old/include/SExposedVideoData.h
76d75
< //! The used display
78,79d76
<
< //! The drawing window ID
81,83d77
<
< //! The drawable area ID
< unsigned long X11Drawable;
diff -r -x '*.o' irrlicht-1.4/source/Irrlicht/CIrrDeviceLinux.cpp irrlicht-1.4_old/source/Irrlicht/CIrrDeviceLinux.cpp
27c27
< IVideoDriver* createOpenGLDriver(const core::dimension2d<s32>& screenSize, Window window,
---
> IVideoDriver* createOpenGLDriver(const core::dimension2d<s32>& screenSize,
45d44
< Window externalWindow,
83c82
< if (!createWindow(windowSize, bits, externalWindow))
---
> if (!createWindow(windowSize, bits))
163c162,163
< bool CIrrDeviceLinux::createWindow(const core::dimension2d<s32>& windowSize, u32 bits, Window externalWindow)
---
> bool CIrrDeviceLinux::createWindow(const core::dimension2d<s32>& windowSize,
> u32 bits)
511,513c511
< if(!externalWindow)
< {
< window = XCreateWindow(display,
---
> window = XCreateWindow(display,
519,528d516
< }
< else
< {
< window = XCreateWindow(display,
< externalWindow,
< 0, 0, Width, Height, 0, visual->depth,
< InputOutput, visual->visual,
< CWBorderPixel | CWColormap | CWEventMask,
< &attributes);
< }
642c630
< VideoDriver = video::createOpenGLDriver(windowSize, window, Fullscreen, StencilBuffer, FileSystem, vsync, AntiAlias);
---
> VideoDriver = video::createOpenGLDriver(windowSize, Fullscreen, StencilBuffer, FileSystem, vsync, AntiAlias);
1336d1323
< (Window)(param.WindowId),
diff -r -x '*.o' irrlicht-1.4/source/Irrlicht/CIrrDeviceLinux.h irrlicht-1.4_old/source/Irrlicht/CIrrDeviceLinux.h
53c53
< Window window, const char* version);
---
> const char* version);
93c93
< bool createWindow(const core::dimension2d<s32>& windowSize, u32 bits, Window externalWindow);
---
> bool createWindow(const core::dimension2d<s32>& windowSize, u32 bits);
diff -r -x '*.o' irrlicht-1.4/source/Irrlicht/COpenGLDriver.cpp irrlicht-1.4_old/source/Irrlicht/COpenGLDriver.cpp
1d0
<
183c182
< COpenGLDriver::COpenGLDriver(const core::dimension2d<s32>& screenSize, Window window, bool fullscreen, bool stencilBuffer, io::IFileSystem* io, bool vsync, bool antiAlias)
---
> COpenGLDriver::COpenGLDriver(const core::dimension2d<s32>& screenSize, bool fullscreen, bool stencilBuffer, io::IFileSystem* io, bool vsync, bool antiAlias)
195,196c194
< ExposedData.OpenGLLinux.X11Drawable = XWindow;
< ExposedData.OpenGLLinux.X11Window = window;
---
> ExposedData.OpenGLLinux.X11Window = XWindow;
2387c2385
< IVideoDriver* createOpenGLDriver(const core::dimension2d<s32>& screenSize, Window window,
---
> IVideoDriver* createOpenGLDriver(const core::dimension2d<s32>& screenSize,
2391c2389
< return new COpenGLDriver(screenSize, window, fullscreen, stencilBuffer,
---
> return new COpenGLDriver(screenSize, fullscreen, stencilBuffer,
diff -r -x '*.o' irrlicht-1.4/source/Irrlicht/COpenGLDriver.h irrlicht-1.4_old/source/Irrlicht/COpenGLDriver.h
83c83
< COpenGLDriver(const core::dimension2d<s32>& screenSize, Window window, bool fullscreen,
---
> COpenGLDriver(const core::dimension2d<s32>& screenSize, bool fullscreen,