Direct3D 11 viewport inside Windows Forms

Started by
7 comments, last by 0254378520938 6 years, 8 months ago

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?

 

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();
}

 

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).

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

 

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

 

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.

Ah, apologize, I've misunderstood :P

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.

 

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

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

This topic is closed to new replies.

Advertisement