DirectX Wrapper/Hooking question

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
EK
Posts: 5
Joined: Fri Jul 15, 2005 12:23 am

DirectX Wrapper/Hooking question

Post by EK »

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?
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

see this , may be it will help you somehow.

http://www.irrforge.org/index.php/Using ... h_Irrlicht
EK
Posts: 5
Joined: Fri Jul 15, 2005 12:23 am

Post by EK »

Exactly what I needed thanks!
Listing
Posts: 12
Joined: Wed Jan 28, 2009 9:30 am

Post by Listing »

Sorry to dig this extremely old thread up but I try to do the same thing and the link is offline
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

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.
Listing
Posts: 12
Joined: Wed Jan 28, 2009 9:30 am

Post by Listing »

Thanks for your fast help!
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.
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
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Hmm, the beginScene parameter also takes an ExposedVideo struct, which you can fill with your dx9 handle. Should work, too.
Listing
Posts: 12
Joined: Wed Jan 28, 2009 9:30 am

Post by Listing »

hybrid wrote:Hmm, the beginScene parameter also takes an ExposedVideo struct, which you can fill with your dx9 handle. Should work, too.
Works quite well with the following code (proof of concept):

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
}
However, I expected this to draw a white line on the blue background i am drawing via DirectX, but it draws a white line on a black background. Is there any way to avoid Irrlicht wiping out the current image? Because I only want to draw the UI with it and the actual game should still be visible.

Greetings
Listing
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

That's probably because you call:

Code: Select all

device->getVideoDriver()->beginScene(true,true,video::SColor(0,0,0,0),exposedData); 
when you should:

Code: Select all

device->getVideoDriver()->beginScene(false,true,video::SColor(0,0,0,0),exposedData);
Listing
Posts: 12
Joined: Wed Jan 28, 2009 9:30 am

Post by Listing »

greenya wrote:That's probably because you call:

Code: Select all

device->getVideoDriver()->beginScene(true,true,video::SColor(0,0,0,0),exposedData); 
when you should:

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.

Here is the full code of my minimal example if you want to test it yourself :-( It basically draws a simple triangle with a blue background if you comment the irrlicht hook out. If not it draws a white line on a black background...

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;
in the beginScene function
Post Reply