Jump to content
  • Advertisement
Jiraya

Direct3D 11 viewport inside Windows Forms

Recommended Posts

I am aiming to learn Windows Forms with the purpose of creating some game-related tools, but since I know absolutely nothing about Windows Forms yet, I wonder:

Is it possible to render a Direct3D 11 viewport inside a Windows Form Application? I see a lot of game editors that have a region of the window reserved for displaying and manipulating a 3D or 2D scene. That's what I am aiming for.

Otherwise, would you suggest another library to create a GUI for game-related tools?

 

EDIT:

I've found a tutorial here in gamedev that shows a solution:

Though it's for D3D9, I'm not sure if it would work for D3D11?

 

Edited by thefoxbard

Share this post


Link to post
Share on other sites
Advertisement

I think it is absolutely possible, since the book "3d game programming with directX 11" uses that as a framework to show its 3d examples, here's the code of said framework, D3DApp::InitMainWindow() in particular is the function in that .cpp that creates a window (and the InitDirect3D uses said window handle to fill the field OutputWindow of the swap chain description struct, which is then used to create the swap chain), you just need to derive a class from this D3DApp class and use it inside the WinMain() function (you can see an example on MSDN site for WinMain(), is the main() function you use with windows apps)

Edit: for clarity, I'll show you:

#include <Windows.h>
#include "Matrix2DClient.h" //this is my class that inherits from D3DApp or D2DApp

int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdLine, int show)
{	
	Matrix2DClient client(instance, L"Direct2D Client", 1280.f, 960.f);
	if(!client.Init())	{
		return 0;
	}

	return client.Run();
}

 

Edited by MarcusAseth

Share this post


Link to post
Share on other sites
4 hours ago, thefoxbard said:

Otherwise, would you suggest another library to create a GUI for game-related tools?

WPF (thus .NET) is the currently sanctioned way to do UI for Windows right now. WinForms is deprecated.

There is also Qt if you want something native (and multi platform).

Edited by TheChubu

Share this post


Link to post
Share on other sites

 

13 hours ago, TheChubu said:

WPF (thus .NET) is the currently sanctioned way to do UI for Windows right now. WinForms is deprecated.

There is also Qt if you want something native (and multi platform).

WPF seems interesting, but apparently you're forced to use D3D9 for displaying a Direct3D Surface/Frame?

http://jmorrill.hjtcentral.com/Home/tabid/428/EntryId/437/Direct3D-10-11-Direct2D-in-WPF.aspx

https://social.msdn.microsoft.com/Forums/en-US/9e203954-03e3-4efc-972c-548eaa6ae815/wpf-using-directx-11?forum=wpf

 

Edited by thefoxbard
Quoted on wrong post

Share this post


Link to post
Share on other sites
16 hours ago, MarcusAseth said:

I think it is absolutely possible, since the book "3d game programming with directX 11" uses that as a framework to show its 3d examples, here's the code of said framework, D3DApp::InitMainWindow() in particular is the function in that .cpp that creates a window (and the InitDirect3D uses said window handle to fill the field OutputWindow of the swap chain description struct, which is then used to create the swap chain), you just need to derive a class from this D3DApp class and use it inside the WinMain() function (you can see an example on MSDN site for WinMain(), is the main() function you use with windows apps)

Edit: for clarity, I'll show you:


#include <Windows.h>
#include "Matrix2DClient.h" //this is my class that inherits from D3DApp or D2DApp

int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdLine, int show)
{	
	Matrix2DClient client(instance, L"Direct2D Client", 1280.f, 960.f);
	if(!client.Init())	{
		return 0;
	}

	return client.Run();
}

 

Hi Marcus, thanks for the reply!

But isn't this pure Win32 API style? I meant using C# and Windows Forms.

I've found a tutorial here in gamedev that shows a way how to do it. But I'm not sure if it would work in D3D11. I've posted the link in the first post.

Share this post


Link to post
Share on other sites
On 8/14/2017 at 11:43 AM, thefoxbard said:

WPF seems interesting, but apparently you're forced to use D3D9 for displaying a Direct3D Surface/Frame?

Look at the links you provided, they're very old, 2009 and 2010. Simple Google search, from Microsoft itself https://github.com/Microsoft/WPFDXInterop

Quote

WPF DirectX Extensions allow you to easily host DirectX 10 and DirectX 11 content in WPF applications.

 

Share this post


Link to post
Share on other sites
44 minutes ago, TheChubu said:

Look at the links you provided, they're very old, 2009 and 2010. Simple Google search, from Microsoft itself https://github.com/Microsoft/WPFDXInterop

 

Old or new, it seems Microsoft does exactly the same thing:

https://github.com/Microsoft/WPFDXInterop/search?utf8=✓&q=d3d9&type=

 

Apparently, this is done because WPF is implemented in D3D9 (probably for hardware compatibility purposes).

I guess it works, but not without its problems:

https://github.com/Microsoft/WPFDXInterop/issues

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!