Sign in to follow this  

DirectX - SlimDX - LayeredWindow with D2DGdiInteropRenderTarget

This topic is 395 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello!

I am relatively new in DirectX programing and I've some trouble get my program working properly.
The thing I want to achive is a LayeredWindow with hardware acceleration as described in this article: https://msdn.microsoft.com/magazine/ee819134.aspx
I wanna achieve this whole thing in C# with the SlimDX library.

This is my code so far:

	int w = 100;
	int h = 100;
	
	SlimDX.Direct2D.RenderTargetProperties props = new SlimDX.Direct2D.RenderTargetProperties();
	props.Type = SlimDX.Direct2D.RenderTargetType.Default;
	props.PixelFormat = new SlimDX.Direct2D.PixelFormat(SlimDX.DXGI.Format.B8G8R8A8_UNorm, SlimDX.Direct2D.AlphaMode.Premultiplied);
	
	SlimDX.Direct2D.Factory f = new SlimDX.Direct2D.Factory(SlimDX.Direct2D.FactoryType.SingleThreaded);

	SlimDX.Direct3D10_1.Device1 d = new SlimDX.Direct3D10_1.Device1(DriverType.Hardware, DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_0);
	
	Texture2DDescription description = new Texture2DDescription();
	description.ArraySize = 1;
	description.BindFlags = BindFlags.RenderTarget;
	description.Format = SlimDX.DXGI.Format.B8G8R8A8_UNorm;
	description.Width = w;
	description.Height = h;
	description.MipLevels = 1;
	description.SampleDescription = new SlimDX.DXGI.SampleDescription() {
		Count = 1
	};
	description.OptionFlags = ResourceOptionFlags.GdiCompatible;
	Texture2D texture = new Texture2D(d, description);
	SlimDX.DXGI.Surface surface = texture.AsSurface();
	SlimDX.Direct2D.RenderTarget target = SlimDX.Direct2D.RenderTarget.FromDXGI(f, surface, props);

	target.BeginDraw();
	SlimDX.Direct2D.GdiInteropRenderTarget gdiTarget = new SlimDX.Direct2D.GdiInteropRenderTarget(target);

	IntPtr dc = gdiTarget.GetDC(SlimDX.Direct2D.DeviceContextInitializeMode.Copy);

The following error occours at the last line: "SlimDX.Direct2D.Direct2DException: D2DERR_TARGET_NOT_GDI_COMPATIBLE: The render target is not compatible with GDI (-2003238886)"
I don't understand why. I've set my Texture OptionFlags to "ResourceOptionFlags.GdiCompatible".
 

Hopefully someone with more experience can help me to achieve my goal.

Best regards!

Share this post


Link to post
Share on other sites

This topic is 395 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this