* Reset branch for WPF changes * Convert BMP to PNG; fix link-out-of-scope err * Add snippets for WPF... 6794 files!!!! * Add missing snippets * update file updated between migration * Fix paths to include * update breadcrumb and toc * fix index links * fix index links * fix index links * fix markdown
5.9 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | |||
|---|---|---|---|---|---|---|---|
| Create Direct3D9 Content for Hosting | 03/30/2017 |
|
|
286e98bc-1eaa-4b5e-923d-3490a9cca5fc |
Walkthrough: Creating Direct3D9 Content for Hosting in WPF
This walkthrough shows how to create Direct3D9 content that is suitable for hosting in a Windows Presentation Foundation (WPF) application. For more information on hosting Direct3D9 content in WPF applications, see WPF and Direct3D9 Interoperation.
In this walkthrough, you perform the following tasks:
-
Create a Direct3D9 project.
-
Configure the Direct3D9 project for hosting in a WPF application.
When you are finished, you will have a DLL that contains Direct3D9 content for use in a WPF application.
Prerequisites
You need the following components to complete this walkthrough:
-
Visual Studio 2010.
-
DirectX SDK 9 or later.
Creating the Direct3D9 Project
The first step is to create and configure the Direct3D9 project.
To create the Direct3D9 project
-
Create a new Win32 Project in C++ named
D3DContent.The Win32 Application Wizard opens and displays the Welcome screen.
-
Click Next.
The Application Settings screen appears.
-
In the Application type: section, select the DLL option.
-
Click Finish.
The D3DContent project is generated.
-
In Solution Explorer, right-click the D3DContent project and select Properties.
The D3DContent Property Pages dialog box opens.
-
Select the C/C++ node.
-
In the Additional Include Directories field, specify the location of the DirectX include folder. The default location for this folder is %ProgramFiles%\Microsoft DirectX SDK (version)\Include.
-
Double-click the Linker node to expand it.
-
In the Additional Library Directories field, specify the location of the DirectX libraries folder. The default location for this folder is %ProgramFiles%\Microsoft DirectX SDK (version)\Lib\x86.
-
Select the Input node.
-
In the Additional Dependencies field, add the
d3d9.libandd3dx9.libfiles. -
In Solution Explorer, add a new module definition file (.def) named
D3DContent.defto the project.
Creating the Direct3D9 Content
To get the best performance, your Direct3D9 content must use particular settings. The following code shows how to create a Direct3D9 surface that has the best performance characteristics. For more information, see Performance Considerations for Direct3D9 and WPF Interoperability.
To create the Direct3D9 content
-
Using Solution Explorer, add three C++ classes to the project named the following.
CRenderer(with virtual destructor)CRendererManagerCTriangleRenderer -
Open Renderer.h in the Code Editor and replace the automatically generated code with the following code.
[!code-cppSystem.Windows.Interop.D3DImage#RendererH]
-
Open Renderer.cpp in the Code Editor and replace the automatically generated code with the following code.
[!code-cppSystem.Windows.Interop.D3DImage#RendererCPP]
-
Open RendererManager.h in the Code Editor and replace the automatically generated code with the following code.
-
Open RendererManager.cpp in the Code Editor and replace the automatically generated code with the following code.
[!code-cppSystem.Windows.Interop.D3DImage#RendererManagerCPP]
-
Open TriangleRenderer.h in the Code Editor and replace the automatically generated code with the following code.
[!code-cppSystem.Windows.Interop.D3DImage#TriangleRendererH]
-
Open TriangleRenderer.cpp in the Code Editor and replace the automatically generated code with the following code.
[!code-cppSystem.Windows.Interop.D3DImage#TriangleRendererCPP]
-
Open stdafx.h in the Code Editor and replace the automatically generated code with the following code.
[!code-cppSystem.Windows.Interop.D3DImage#StdafxH]
-
Open dllmain.cpp in the Code Editor and replace the automatically generated code with the following code.
[!code-cppSystem.Windows.Interop.D3DImage#DllMain]
-
Open D3DContent.def in the code editor.
-
Replace the automatically generated code with the following code.
LIBRARY "D3DContent" EXPORTS SetSize SetAlpha SetNumDesiredSamples SetAdapter GetBackBufferNoRef Render Destroy -
Build the project.
Next Steps
- Host the Direct3D9 content in a WPF application. For more information, see Walkthrough: Hosting Direct3D9 Content in WPF.