I finally found a way to get this working, but it's probably not the best solution...
So anyways, here's a method which returns an ExposedVideoData object that will work with both D3D and GL.
Code: Select all
public ExposedVideoData GetVideoDataFromHWND(IntPtr hwnd, IrrlichtDevice device, IrrlichtCreationParameters creationParams)
{
VideoDriver driver = device.VideoDriver;
if (driver.DriverType == DriverType.OpenGL)
{
ContextManager contextMan = device.ContextManager;
ExposedVideoData dummyVideoData = driver.ExposedVideoData;
dummyVideoData.WindowID = hwnd;
contextMan.Initialize(creationParams, dummyVideoData);
contextMan.GenerateSurface();
contextMan.GenerateContext();
ExposedVideoData videoData = contextMan.Context;
videoData.RenderingContext = dummyVideoData.RenderingContext;
return videoData;
}
else
{
ExposedVideoData videoData = driver.ExposedVideoData;
videoData.WindowID = hwnd;
return videoData;
}
}
It needs the IrrlichtCreation params you used for creating your IrrlichtDevice, e.g. like this:
Code: Select all
IrrlichtCreationParameters deviceParams = new IrrlichtCreationParameters();
deviceParams.DriverType = DriverType.OpenGL;
deviceParams.WindowID = <some_HWND>; //put a handle here, so it does not create a separate Irrlicht window
device = IrrlichtDevice.CreateDevice(deviceParams);
You have to pass the object you got from GetVideoDataFromHWND with every BeginScene call corresponding to that handle.
Also, after you've initialized the ExposedVideoData,
loading textures (which may be loaded automatically with models!) will fail!
So you have to load them before or, you can reset the video data before loading the textures every time like this:
Code: Select all
public static bool ResetContext(IrrlichtDevice device)
{
ContextManager contextMan = device.ContextManager;
if (contextMan != null)
return contextMan.ActivateContext(device.VideoDriver.ExposedVideoData);
return true;
}
After this, you won't have to re-create the ExposedVideoData objects, they will continue to work.
I hope this is helpful