Hi,
I just started with Irrlicht(Lime) and want to render different views on different WinForm panels.
I do for each panel a function beginScene with a videodata parameter containing the current panel handle.
When I start the application with driver type Direct3D9 it works exactly like expected.
When I use OpenGL it only renders in the first panel (that one I provided at createDevice) and no other panel.
How do I get it working with OpenGL?
beginScene VideoData is ignored when using OpenGL driver
Re: beginScene VideoData is ignored when using OpenGL driver
Hey there!
But looking into the source code, it looks like the OpenGL driver contains the necessary code for that.
So maybe you are passing a (partly) invalid piece of videoData.
How do you create it? Just by calling "new ExposedVideoData()"?
This is how I'd do it (with Lime):
I hope this works.
So this means it may or may not work with all drivers I guess.Documentation wrote:videoData Handle of another window, if you want the bitmap to be displayed on another window. If this is an empty element, everything will be displayed in the default window. Note: This feature is not fully implemented for all devices.
But looking into the source code, it looks like the OpenGL driver contains the necessary code for that.
So maybe you are passing a (partly) invalid piece of videoData.
How do you create it? Just by calling "new ExposedVideoData()"?
This is how I'd do it (with Lime):
Code: Select all
VideoDriver driver = ...; //I guess you got a video driver from somewhere...
ExposedVideoData data = driver.ExposedVideoData;
data.WindowID = ...; //replace with your window ID
//now you can pass "data" with your BeginScene call
driver.BeginScene(..., data, ...);
Re: beginScene VideoData is ignored when using OpenGL driver
Yes I use the 'old' ExposedVideoData that I got from the driver and change the WindowID just like in your example.
Looks like I have to stick with Direct3D9
Looks like I have to stick with Direct3D9
Re: beginScene VideoData is ignored when using OpenGL driver
Hey there,
I looked into this further, and it looks like it should work, and it probably works with Linux, but for the window handle is simply ignored in the code, it only changes the context.
So if you are able to generate a second context, you will be able to render into a separate window / panel.
The thing is there actually is a ContextManager class, which allows you to generate a new context, but it sadly re-uses the handle set in the constructor.
I could not find a workaround, and this looks like something really useful, so I hope it gets implemented soon.
Sorry :/
I looked into this further, and it looks like it should work, and it probably works with Linux, but for the window handle is simply ignored in the code, it only changes the context.
So if you are able to generate a second context, you will be able to render into a separate window / panel.
The thing is there actually is a ContextManager class, which allows you to generate a new context, but it sadly re-uses the handle set in the constructor.
I could not find a workaround, and this looks like something really useful, so I hope it gets implemented soon.
Sorry :/
Workaround
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.
It needs the IrrlichtCreation params you used for creating your IrrlichtDevice, e.g. like this:
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:
After this, you won't have to re-create the ExposedVideoData objects, they will continue to work.
I hope this is helpful
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;
}
}
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);
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;
}
I hope this is helpful
Re: beginScene VideoData is ignored when using OpenGL driver
Hi, thank you so much for your solution!