DirectX Wrapper/Hooking question
DirectX Wrapper/Hooking question
I have created a wrapper for DirectX for the purpose of drawing on top on games. I hook Direct3DCreate9 and return a pointer to my wrapper then I use the normal DirectX device for drawing.
I would like to use the Irrlicht Engine for drawing. Is there a way to use the engine even if I have created my own device?
I would like to use the Irrlicht Engine for drawing. Is there a way to use the engine even if I have created my own device?
-
Emil_halim
- Posts: 518
- Joined: Tue Mar 29, 2005 9:02 pm
- Location: Alex,Egypt
- Contact:
Magic 2d Library For Irrlicht : http://www.freewebs.com/bcxgl/index.htm
http://www.freewebs.com/bcxdx/index.htm
http://groups.yahoo.com/group/bcxdxc/
http://www.freewebs.com/bcxdx/index.htm
http://groups.yahoo.com/group/bcxdxc/
Thanks for your fast help!
The problem is that I also want the tool to be able to hook DirectX "on the fly" (attaching to the process). This means when I attach to the process the DX9 handle is already created and I need Irrlicht to use this handle to draw my stuff. (I will call it between the BeginScene and EndScene used by the original program)hybrid wrote:Can't you do the reverse: Use Irrlicht to create the device, get ExposedVideoData and do the rendering on that DX9 handle? Otherwise it's easiest to give IRrlicht the window upon device creation, which then will be reused in Irrlicht instead of creating a new window.
Works quite well with the following code (proof of concept):hybrid wrote:Hmm, the beginScene parameter also takes an ExposedVideo struct, which you can fill with your dx9 handle. Should work, too.
Code: Select all
// this is the function used to render a single frame
IrrlichtDevice* device = NULL;
HWND hWnd;
void render_frame(void)
{
// clear the window to a deep blue
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);
d3ddev->BeginScene(); // begins the 3D scene
// IRRLICH DIRECTX HOOK
if(!device)
{
//Setup
irr::SIrrlichtCreationParameters params;
params.AntiAlias = true;
params.Bits = 32;
params.DriverType = video::EDT_DIRECT3D9;
params.EventReceiver = 0;
params.Fullscreen = false;
params.WindowId = hWnd;
params.WindowSize.set(800,600);
params.WithAlphaChannel = true;
device = createDeviceEx(params);
}
video::SExposedVideoData exposedData = device->getVideoDriver()->getExposedVideoData();
exposedData.D3D9.D3DDev9 = d3ddev;
device->getVideoDriver()->beginScene(true,true,video::SColor(0,0,0,0),exposedData);
device->getVideoDriver()->draw2DLine(core::position2di(10,10),core::position2di(100,100));
device->getVideoDriver()->endScene();
// END IRRLICHT HOOK
d3ddev->EndScene(); // ends the 3D scene
d3ddev->Present(NULL, NULL, NULL, NULL); // displays the created frame on the screen
}
Greetings
Listing
That's probably because you call:
when you should:
Code: Select all
device->getVideoDriver()->beginScene(true,true,video::SColor(0,0,0,0),exposedData); Code: Select all
device->getVideoDriver()->beginScene(false,true,video::SColor(0,0,0,0),exposedData);It changed something. Now it always draws a black background no matter which color I choose.greenya wrote:That's probably because you call:when you should:Code: Select all
device->getVideoDriver()->beginScene(true,true,video::SColor(0,0,0,0),exposedData);Code: Select all
device->getVideoDriver()->beginScene(false,true,video::SColor(0,0,0,0),exposedData);
Here is the full code of my minimal example if you want to test it yourself
Thanks for your help
EDIT:
I solved it... The problem was that the device in exposedData wasn't even completely read by irrlicht (cannot be used to set the driver).
You have to modify the CD3D9Driver.cpp of the Irrlicht distribution and
add
Code: Select all
pID3DDevice = videoData.D3D9.D3DDev9;